Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Put a watch on a recordset ??

Discussion in 'Information Technology' started by SpookiePower, Jul 28, 2006.

  1. SpookiePower

    SpookiePower
    Expand Collapse
    Guest

    Is it possible to see what a recordset holds by using a watch ?

    I have this code line -

    Dim rs As DAO.Recordset
    rs = db.OpenRecordset("SELECT.......

    where I put the result of a sql into a recordset.
    I have tryed to add a watch on the rs, but it does not shows the result of the sql.

    Can someone help me ?

    --
    My PhotoGallery
    www.photo.activewebsite.dk
     
  2. Loading...


  3. strive4peace

    strive4peace
    Expand Collapse
    Guest

    you cannot see what is has using a watch, but here is
    something else you can do:

    '~~~~~~~~~~~~~~~~~
    Dim rs As DAO.Recordset, strSQL as string
    strSQL = "SELECT......."
    debug.print strSQL
    set rs = db.OpenRecordset(strSQL, dbopendynaset)
    stop (or set breakpoint if you want to see the reaults right
    away)
    '~~~~~~~~~~~~~~~~~

    now, the SQL statement is in the debug window
    press CTRL-G to Goto the debug window
    copy the SQL statement
    make a new query
    switch to SQL view (View, SQL from menu)
    paste the statement
    ! to run it

    while I am programming and testing, I often leave a query
    open in SQL view for testing statements

    Warm Regards,
    Crystal
    MVP Microsoft Access

    remote programming and training
    strive4peace2006 at yahoo.com
    *
    Have an awesome day ;)


    SpookiePower wrote:
    > Is it possible to see what a recordset holds by using a watch ?
    >
    > I have this code line -
    >
    > Dim rs As DAO.Recordset
    > rs = db.OpenRecordset("SELECT.......
    >
    > where I put the result of a sql into a recordset.
    > I have tryed to add a watch on the rs, but it does not shows the result of the sql.
    >
    > Can someone help me ?
    >
     
  4. SpookiePower

    SpookiePower
    Expand Collapse
    Guest

  5. strive4peace

    strive4peace
    Expand Collapse
    Guest

    setting a breakpoint, debugging, error handler

    you're welcome ;)

    a few more notes --

    if you think that the OpenRecordset statement may throw an
    error, or you wish to ensure that the recordset is correct
    before continuing, you may wish to set a breakpoint on it.

    ~~~~~ setting a breakpoint ~~~~~

    To Set a Breakpoint with the mouse, click in the shaded gray
    region just to the left of the white margin area on the same
    line as the statement where you want the code to stop.

    If a breakpoint is set, a RED DOT will appear in the gray
    area just to the left of the white margin area for that line.

    F9 --> toggle Breakpoint on current line

    from the menu --> Debug, Toggle Breakpoint

    To clear a breakpoint, simply click on the red dot, press
    F9, or Toggle Breakpoint from the menu.

    When your program executes, it will stop on each Breakpoint
    line and highlight it

    While you are in this mode of suspended execution, you can:

    -- F8 to execute the next statement --

    F8 will stop on every line -- even if code branches to
    another procedure

    -- SHIFT-F8 to execute next statement --
    -- in current procedure --

    This is handy if you know that the external sub or function
    call does not have errors and you have no need to examine
    any variables.

    -- F5 to continue running normally --

    (from the menu: Run, Run)

    --- skipping code ---
    if you see that you need to fix things and want to just end
    the program,

    right-click on the line where your "exit code" starts
    choose SET NEXT STATEMENT from the shortcut menu

    ~~~~~ Stop vs Breakpoint ~~~~~

    Breakpoints are not saved. The next time you open your
    database, you will have to set them again. Using STOP as a
    statement in your code is saved if you save your code while
    it is there.

    ~~~~~ manually Breaking a program ~~~~~

    press CTRL-BREAK during execution to suspend code. The
    problem with this is that the program is not always paying
    attention to the keyboard. You can force it to pay
    attention by using DoEvents in your code.

    DoEvents

    ~~~~~ DoEvents ~~~~~

    DoEvents is used to make VBA pay attention to what is
    currently happening and look to see if the OS (Operating
    System) has any requests.

    i.e.: if you have a loop and want to be able to BREAK it
    with CTRL-BREAK (as opposed to whenever the processor
    decides to acknowledge the keyboard interrupt), put DoEvents
    into the loop

    Sometimes DoEvents is necessary to make changes show up
    right away -- like if you are writing to a form from code
    that is not behind the form (code in a general procedure or
    behind another form or report), or refreshing table
    definitions after changing data with an SQL statement.

    Using DoEvents does slow down execution and can cause other
    problems (such as forgetting what file the system is on when
    looping through a directory using Dir(filespec) and then
    Dir() to find next file for the same spec.

    A DoEvents is done when you use MsgBox, or are stepping
    through code (since it has to pay attention to the keyboard)

    It is a good way to say, "Wake Up!"

    Here is some generic code for an error handler, a set of
    statements that reports errors and, which is not done here,
    handles them according to their value. For instance if you
    are deleting a table before you make a table in code and it
    is not there to delete, a certain error number will report
    this. If you want to skip that error, you can use Resume
    Next (go to the line after the line with the problem)

    ~~~~~ Exit Code and Error Handler ~~~~~

    '----- put this line at top of procedure:

    On Error GoTo proc_Error


    '... other statements


    '------ add these lines to the bottom of the procedure

    proc_Exit:

    'if everything executed normally, exit the procedure
    Exit sub

    'Exit Function -- use if the procedure is a function


    proc_Error:
    MsgBox Err.Description, , _
    "ERROR " & Err.Number & " procedurename"

    'press F8 to step through lines of code
    'comment next line after debugged
    Stop : Resume

    resume proc_Exit

    End Sub/Function

    '~~~~~~~~~~~~~~~~~~~~~~~~~

    If, during execution, an error flag is raised, execution
    will go to the error handler, which is denoted with a line
    label

    proc_Error:

    --- Line Label ---

    A line label is a word (that is not a statement) before a
    colon at the beginning of the line. Line Labels are used
    for branching code execution.

    You can change the label before the colon but it cannot
    contain spaces.

    A colon can also be used to separate executable statements
    so that they can be written on the same line, as with
    Stop : Resume

    --- Error Handler Comments ---

    When an error is raised and execution goes to the error
    handler, a message box is issued describing the problem
    (with the MsgBox statement), and then the code is STOPped with

    Stop

    Press the F8 key ( which is the shortcut key to single-step
    through code) once to go to the next line

    Resume

    tells the process to go back to the line that caused the
    problem.

    press F8 again to go to the actual offending line

    You can then fix the problem, save your code, and then
    resume the code
    (right-click on the line where you want to resume
    and choose "Set Next Statement" from the shortcut menu)

    then, either F5 to RUN (from the menu bar: Run, Run)
    or F8 to continue stepping through code

    OR
    to stop the procedure
    (from the menu bar: Run, Reset)

    if, at any point during execution, you want to STOP the
    code, press CTRL-BREAK -- you may have to hold the Control
    key and repeatedly press the Pause/Break key until Access
    pays attention to the keyboard. In your code, you can put
    in a line that MAKES it pay attention to the keyboard:

    DoEvents

    If I have a loop, I often put DoEvents into the loop while I
    am developing.

    When you are chasing errors

    ~~~~~ Immediate Window ~~~~~

    In the Immediate Window, you can get immediate results to
    questions -- such as

    ? myVariablename [ENTER]

    On the next line will be printed the current value of a
    variable named "myVariablename"

    You can also set variables to a different value

    myVariablename = "something_else"

    you can type keywords such as OpenReport or Resume
    and press F1 to get immediate help (without navigating!) to
    that keyword

    ~~~~~ Debug Window (CTRL-G) ~~~~~

    The term "Debug Window" is often used to refer to the
    Immediate Window.

    You can print to the debug window in code by using the Print
    method of the Debug object in VBA code

    Debug.Print myVariablename

    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    Warm Regards,
    Crystal
    MVP Microsoft Access

    remote programming and training
    strive4peace2006 at yahoo.com
    *
    Have an awesome day ;)


    SpookiePower wrote:
    > Thanks :)
    >
    >
     

Share This Page