Results 1 to 4 of 4
  1. #1
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96

    vba code running in wrong order??

    I am having some trouble with the listed code, but I'm not sure if the problem is within the code or the form:

    Code:
    Private Sub cmdClose_Click()
     Dim Msg, Style, Title, Response, MyString
    If [Amt_EarlyEFT] = 0 Then
          Msg = "Do you want to submit with a 0.00 amount?"
          Style = vbYesNo + vbCritical + vbDefaultButton2
          Title = "Empty Amount"
          Response = MsgBox(Msg, Style, Title, Help, Ctxt)
          If Response = vbYes Then   ' User chose Yes.
             DoCmd.RunMacro ("manual input form - CLOSE")
          Else   ' User chose No.
             DoCmd.GoToControl ("Amt_EarlyEFT")
          End If
     Else: DoCmd.RunMacro ("manual input form - CLOSE")
     End If
    End Sub
    This code runs as expected, but it runs prior to the record on the form being added to the table. The referenced macro runs several append queries and then clears a temp table, so if I run the process six times in a row, the first five entries move perfectly and the last one gets stranged in the temp table. I'm new to programming and most of this code is already borrowed, so I have no idea if I just have things in the wrong order or if I need additional code to add that last record from the form to the table before the macro fires. Any help would be greatly appreciated!
    Last edited by RuralGuy; 08-30-2013 at 11:16 AM. Reason: Added code tags and indenting

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I strongly recommend you remove the ":" after that Else and move the code to the next line. Access can get confused when you mix single line code and multiline code in the same procedure.

  3. #3
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96
    Thank you very much!

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You're welcome. Glad we could help. I take it that was all it took to resolve the issue?

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

Similar Threads

  1. Running queries, VIA VB, but not running in Order
    By mike02 in forum Programming
    Replies: 6
    Last Post: 06-01-2013, 07:07 AM
  2. macro running in order
    By dumbledown in forum Access
    Replies: 2
    Last Post: 09-03-2012, 08:05 AM
  3. Replies: 11
    Last Post: 07-08-2011, 02:12 PM
  4. What's wrong with my code?
    By Dalagrath in forum Forms
    Replies: 11
    Last Post: 05-18-2011, 04:34 PM
  5. What is wrong with this code?
    By nkenney in forum Forms
    Replies: 2
    Last Post: 11-16-2009, 03:04 PM

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