Results 1 to 3 of 3
  1. #1
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91

    Run Append Query From If Statement

    Hi, I think the answer is probably very simple but I can't seem to get this to work so hope someone can help.... I want to run an append query to add a new record to a table on close of form when a condition is met in a textbox in my form. VBA is not my strong point and the code I have is:

    [Private Sub Form_Close()
    If Me.Text273 = "COMPLETE" Then
    DoCmd.OpenQuery "Apps Post Complete", acNormal, acAdd
    End If
    End Sub]

    I have changed this and included a message and it works perfectly up to a point..... I just can't get the form to close if the message is not shown or when it did the message appeared again afterwards.
    The new code is:
    [Private Sub Command91_Click()
    If Me.Text287 = "COMPLETE" Then
    Dim myResponse
    myResponse = MsgBox("Click Complete Button to update Post Table", vbYesNo, "UPDATE POST TABLE")
    If myResponse = vbYes Then
    DoCmd.RunMacro "AppsCMPTUpdate"
    If myResponse = vbNo Then
    DoCmd.Close


    Else
    DoCmd.Close
    End If
    End If
    End If
    End Sub]


    Would be grateful of any assistance please.
    Last edited by scoe; 04-02-2014 at 06:45 AM. Reason: moved on but still have a problem

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Rather than create a macro that then runs the Action query you could just run the query straight from VBA

    Instead of
    DoCmd.RunMacro "AppsCMPTUpdate"
    use
    application.execute "NameOfQuery"

    If you want the form to close after the query is run you could
    application.execute "NameOfQuery"
    docmd.close acform, "NameOfForm"

  3. #3
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Thank you, I'll give it ago

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

Similar Threads

  1. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  2. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  3. Replies: 7
    Last Post: 07-21-2011, 01:01 PM
  4. Append Query with IIF statement
    By Cheshire101 in forum Queries
    Replies: 5
    Last Post: 09-16-2010, 12:51 PM
  5. Append query won't append
    By yelkenli in forum Queries
    Replies: 5
    Last Post: 02-12-2010, 11:19 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