Results 1 to 9 of 9
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Debugging VBA code

    The db program that works fails at a certain point. This failure point is outlined in the VBA when I ask for debug. However, when I want to print it out, the print command in the drop down file menu is greyed out. Thus I cannot print this stuff out.



    How can I print it out? I usually open a form in design view and select a control on the form, go to properties, select event, and then look at the code. That will not work here. I am not sure what form (if any) the code is associated with, but I would sure like to try and find the source of the runtime error.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    To stop debug mode there is a little square stop sign at the top. However this will remove the highlighted line.

    you can press print screen on your keyboard and then print that. a good tool for this is lightshot if you google that. you can select an area on screen and print directly or save. hope this helps.

  3. #3
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Not sure why you want to print it out. I use a screen capture utility (like Greenshot) to capture an error message so I can then look at the code and the message. Setting breakpoints above the location where you think the error occurs works well too. An invaluable help is to include a Resume line in the error handling section of each module:
    Code:
    cmdFilter_Click_Error:    Call ErrorHandler(MODULE_NAME, "cmdFilter_Click", Err, Err.Description)
        Resume cmdFilter_Click_Cleanup
        Resume
    Before running the code, set a breakpoint on the first executable line of your error handling section (in my case, Call ErrorHandler...). Then when the error occurs, execution stops on that line. Move the cursor from the breakpoint line to the "Resume" line and press F8. It will take you to the line that caused the error. I presume you include error trapping in your modules? Here is a complete procedure:
    Code:
    Private Sub Form_Open(Cancel As Integer)
    
        On Error GoTo Form_Open_Error
    
        Call FormAutoExec(Me, True)
        
         ...
    
    Form_Open_Cleanup:
        Exit Sub
    
    Form_Open_Error:
        Call ErrorHandler(MODULE_NAME, "cmdCancel_Click", Err, Err.Description)
        Resume Form_Open_Cleanup
        Resume
    End Sub
    Also, this link may help you learn more about debugging techniques: http://www.fmsinc.com/tpapers/vbacode/debug.asp

  4. #4
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I have SnagIt. This is code that I did not write and some seems to me to be from a library borrowed from who knows where. I just want a gestalt on how this works. Thus I want the whole print out of the code.

    Respectfully,

    Lou Reed

  5. #5
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    If you have SnagIt, then make a picture and post it. Also, can you not do a copy and paste?

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    The screenshot is posted and the db file is attached

    The db is attached in the file along with a screenshot of where the code fails.

    Go to form frmAttendence, select a meeting date in combo box list. Once selected then click on add meeting and you will get
    an error. This is code I did not write. It is there. I am not sure what is does, but it seems some type utlity function
    that would be standard in any db.

    I am curious why it fails.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  7. #7
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    In addition to where the error occurs:

    totalPersonnel = DCount("[MeetingID]", "qryAttendance", "[MeetingID] = " & MeetingID)

    It helps to tell us what the error is:

    Error 2471
    The expression you entered as a query parameter produced this error: '[MeetingID]'

    qryAttendance is not returning a field called MeetingID. Not only that, but MeetingID isn't in either table (tblAttendance or tblPersonnel) that is referenced in the query! Is it instead supposed to be "ysnMeetingID" which is in tblAttendance?

    This sample database is causing you loads of pain. Most times it is better to design your own database from the beginning than try to change an existing database to suit your needs.

  8. #8
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I will have to find out. As I said I did not write that section of code. I apologize for the failure to completely inform you. I thought that once you ran the code the error would
    show up and be self-explanatory. Again, sorry for the omission. I have been a program consultant on many different languages and some times, I fuss at students and tell
    them how can I help you if I do not know what the problem is. I should follow my own advice.

    Again sorry. It is not easy debugging somebody else's code and I should be more succinct in my posts.

    Now it seems like that code is library code. Is there a website where I can get more literature on it.

    That would make my life easier.

    I did check the obvious website in the code's header, but got little help there.

    Respectfully,

    Lou Reed

  9. #9
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    All's good. As it was supplied as a sample database, I doubt the original author(s) would be willing to help you dissect the design and code. Do you have a working document on what processes this database is supposed to automate - including table structures and business requirements? If you do, I would be willing to help you get this working within a week.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Debugging - F8 not stepping through the code?
    By djspod in forum Programming
    Replies: 5
    Last Post: 03-15-2017, 09:05 AM
  2. U for MS AccessSeful DEBUGGING Add-Ins
    By JrMontgom in forum Access
    Replies: 4
    Last Post: 01-02-2016, 03:50 PM
  3. Need some help debugging an INSERT INTO query
    By kagoodwin13 in forum Queries
    Replies: 2
    Last Post: 05-08-2015, 10:12 AM
  4. Debugging
    By eacollie in forum Programming
    Replies: 2
    Last Post: 06-04-2011, 05:29 AM
  5. Debugging help
    By Buakaw in forum Access
    Replies: 3
    Last Post: 02-16-2011, 09:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums