Results 1 to 5 of 5
  1. #1
    jfl59 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2013
    Posts
    5

    VBA code for form button works in debug mode, but not in runtime mode.

    I have some VBA code behind a button to update a table then reset (make some work fields not displaying and clearing out some other fields in the form) the forms display. When testing the form, it appears to be skipping this code as it is not resetting the display. When I turn on a debug break point in the middle of the code, it works correctly. This form currently works correctly in the live access 2007 database. I am converting the whole system to an Access 2013 database and making some enhancements to the new system. There have not been any programming changes to this form yet as I was first testing it in the new Access 2013 database. All of the tables and forms were copy and pasted from the live database to the new database.
    Everything is working fine except this one form.

    Any help would be greatly appreciated.

    Here is a portion of the code:

    ' Add/Update Detail Record.
    If Me.wOdID > 0 Then
    UpdateDtlRcd
    Else
    WriteDtlRcd
    End If

    ' Set form for new item entry.
    ClearEntryFields
    <---- The 'ClearEntryFields' subroutine is the step that appears to be bypassed when debug is off.
    DoCmd.Requery qryOrdersDtl

    End Sub
    ------------------------------------------------------
    Sub ClearEntryFields()

    Me.wOdID = 0
    Me.wItemDesc.Enabled = True
    Me.wItemDesc.Locked = False
    Me.wItemDesc = ""
    Me.wItemDesc.SetFocus
    Me.CmdRequery.Enabled = True

    Me.wItemCde.Visible = False
    Me.wItemType.Visible = False
    Me.wInStock.Visible = False
    Me.wInStock.Value = 0
    Me.wCName.Enabled = True
    Me.wCName.Locked = False
    Me.wCName.Visible = False
    Me.wCNamePhoto.Picture = ""
    Me.wQty.Visible = False
    Me.wQty.Value = Null
    Me.wPkgType.Visible = False
    Me.wPkgType.Value = Null
    Me.wRxPhone.Visible = False
    Me.wRxPhone.Value = Null
    Me.wRxName.Visible = False
    Me.wRxName.Value = Null
    Me.CmdRequeryRx.Enabled = False
    Me.CmdRequeryRx.Visible = False


    Me.wRxNotes.Visible = False
    Me.wRxNotes.Value = Null
    Me.CmdAdd.Enabled = False
    Me.CmdAdd.Caption = "Add/Update"
    Me.CmdCancel.Enabled = False
    Me.CmdDelete.Enabled = False
    Me.CmdExit.Enabled = True
    Me.TxtLastTime.Visible = False

    End Sub

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I have never had good experience with pasting code into class modules that includes event handlers for controls on the form. Functions and sub routines don't seem to be an issue though.

    Maybe you can comment out the event handler for the control and then create another handler using the IDE or the properties window from the form's design view. Then you could paste in the guts from the code you commented out, leaving out "End Sub" etc because Access already created those lines for you.


    For extra measure you could place "Call" before the sub name. Shouldn't matter though. You could try rebuilding the sub too. You could comment out the entire sub, do a compact and repair. Then you could type "Sub ClearEntryFields" and then hit enter. This would give you a place that Access should recognize to place your code....

  3. #3
    jfl59 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2013
    Posts
    5
    Thank you ItsMe for your suggestion. I just tried it, Unfortunately it did not work for me. If you have any other ideas, I am open.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Sounds like the form's module is no good. I would rebuild the form. You can create a new form. You can copy the controls and labels by selecting all of them and then copy paste. Save the VBA from the original form in a text file.

    After that, delete the original form and do a compact and repair. Then, one control at a time, paste the VBA into a new existing routine within the new VBA module. I would take the extra step of creating the procedure/routine before pasting the code. The way I usualy do it is to copy the name of the control and event from the text file and then hit enter. I do this so Access can keep track of the line numbers. Even though the IDE does not display line numbers I believe they are still there. I have managed to goof up modules by dragging procedures around, within the IDE, to place them in a preferable order. Afterwards, the form would start to act funny, much like you describe your symptoms.

    Edit: You could also search the entire DB and all of its modules for "ClearEntryFields". Make sure it does not exist anywhere before you compact and repair and build your new form.
    Last edited by ItsMe; 11-24-2013 at 09:21 PM. Reason: Added a comment

  5. #5
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    I would sanity check by eliminating the module call ClearEntryFields()

    and instead copy/paste in that entire stack of code....

    then there is no excuse for it not running..... and see what you end up with before deciding what to do next.....

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

Similar Threads

  1. Replies: 6
    Last Post: 09-20-2012, 04:22 PM
  2. Replies: 2
    Last Post: 09-01-2011, 10:48 PM
  3. Replies: 5
    Last Post: 08-29-2011, 04:06 PM
  4. Replies: 2
    Last Post: 03-03-2011, 12:48 PM
  5. Replies: 4
    Last Post: 01-14-2011, 10:37 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