Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2002

    Unanswered: docmd openquery syntax help

    I want to do something simple, run a query when a form is closed. I have the following code to do it and Access does't like the syntax. I've tried putting the query name in brackets and that didn't help either.

    ption Compare Database

    Private Sub Form_Close()

    docmd.OpenQuery(find unmatched append query for results and limits,acViewNormal,acEdit)

    End Sub

    Thanks in Advance

  2. #2
    Join Date
    Jun 2004
    DoCmd.OpenQuery "find unmatched append query for results and limits", acViewNormal, acEdit

        Dim stDocName As String
        stDocName = "find unmatched append query for results and limits"
        DoCmd.OpenQuery stDocName, acViewNormal, acEdit
    You really should consider using better names for your queries etc.. Such as qryresults etc...

  3. #3
    Join Date
    Dec 2003
    Dallas, TX


    Hi tmort,

    Take a look at the code below taken directly from my own database where
    I run queries, but in a different way.

    Private Sub cmbProcessJobCharge_Click()
    On Error GoTo Err_cmbProcessJobCharge_Click
    ' Written by "Bud" and passed to DB Forums user for an example.
    'This Prints out the job charge report,saves the records and closes the form'
        Dim stDocName As String
        stDocName = "JobCharge"
        DoCmd.GoToRecord , , acNewRec
        DoCmd.OpenReport stDocName, acNormal
        stDocName = "LaunchPad.PostJobCharge"
        CurrentDb.Execute "PostJobCharge"
        CurrentDb.Execute "UpdateStockedItems"
        DoCmd.Requery "sfrmJobChargesViewAll"
        DoCmd.Requery "JobID"
        'MsgBox "Your records have been processed." & Chr(13) _
        '& "Thank you and have a nice day!", vbExclamation, "Job Charged Notice"
        Exit Sub
        MsgBox Err.Description
        Resume Exit_cmbProcessJobCharge_Click
    End Sub
    Note: the words in BOLD is the command that runs the queries,
    and at the same time avoids the Access Warning Messages you get and doing
    so this way avoids having to do the:
    SetWarnings/True and False as users have often times to set the
    warnings back to True in the end. No muss, no fuss.
    Note: the Italics are the names of my queries
    As suggested by sionus, IF that was the actual name of your Query, then
    by all means think of Re-Naming to something shorter, neater and meaningful.
    That will save lots of typing and typos.

    Anyway, now you have choices and hope either one gets you what you need.
    If not come back and let another somebody take a whack at ya...

    have a great day,

  4. #4
    Join Date
    Sep 2009
    I think his problem was that he had brackets, as in DoCmd ( stuff ), rather than DoCmd stuff, but nobody has mentioned this peculiarity of the syntax

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts