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

    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
    Posts
    92
    Code:
    DoCmd.OpenQuery "find unmatched append query for results and limits", acViewNormal, acEdit
    or

    Code:
        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
    Location
    Dallas, TX
    Posts
    1,004

    Talking

    Hi tmort,

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



    Code:
    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
        JobID.SetFocus
        DoCmd.OpenReport stDocName, acNormal
        
        stDocName = "LaunchPad.PostJobCharge"
        CurrentDb.Execute "PostJobCharge"
        CurrentDb.Execute "UpdateStockedItems"
        
        DoCmd.Requery "sfrmJobChargesViewAll"
        DoCmd.Requery "JobID"
        'DoCmd.Close
        
        'MsgBox "Your records have been processed." & Chr(13) _
        '& "Thank you and have a nice day!", vbExclamation, "Job Charged Notice"
    
        
        
    Exit_cmbProcessJobCharge_Click:
        Exit Sub
    
    Err_cmbProcessJobCharge_Click:
        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,
    Bud

  4. #4
    Join Date
    Sep 2009
    Posts
    11
    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
  •