Results 1 to 2 of 2
  1. #1
    kewelch is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    13

    Query not properly executing within VBA code

    Hi, I'm having a frustrating encounter with an append query. Here is the code I am running to add a record to tblCustomer after filling out the form bound to tblTempCustomer.



    Code:
    Private Sub AddCustomerShippingcb_Click()    
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "TempCustomerAddressesQuery", acViewNormal, acEdit
        ''''DoCmd.RunSQL "Delete [tblTempCustomer].* From [tblTempCustomer];"
        DoCmd.SetWarnings True
        
    End Sub
    When this executes, the record in tblTempCustomer is not appended to tblCustomer. However, if I leave the temporary table alone by not deleting the record (''''DoCmd.RunSQL "Delete...) and then simply run the query from the object list in the main access window, the record appends perfectly fine. Same query, the only difference is that the form is closed since it is running as a dialog box. All help/advice is appreciated, thanks.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The info you entered in the form is probably not saved.
    Try changing the code to:
    Code:
    Private Sub AddCustomerShippingcb_Click()  
       'save the record first
        If Me.Dirty Then
           Me.Dirty = False
        End If
      
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "TempCustomerAddressesQuery", acViewNormal, acEdit
        ''''DoCmd.RunSQL "Delete [tblTempCustomer].* From [tblTempCustomer];"
        DoCmd.SetWarnings True
        
    End Sub


    I'm curious, why not just bind the form to tblCustomer instead of tblTempCustomer??

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

Similar Threads

  1. Code executing without errors, but not working
    By The Professor in forum Programming
    Replies: 13
    Last Post: 02-18-2013, 04:09 PM
  2. Problems Executing SavedQuery in Code
    By RMittelman in forum Programming
    Replies: 4
    Last Post: 06-18-2011, 02:49 PM
  3. Msgbox And Search Code Not Working Properly
    By vampyr07au in forum Forms
    Replies: 1
    Last Post: 05-02-2011, 05:16 PM
  4. Replies: 3
    Last Post: 09-16-2010, 09:50 AM
  5. Executing Query to Excel?
    By objNoob in forum Programming
    Replies: 1
    Last Post: 03-17-2010, 04:59 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