Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006
    Location
    New Kensington, PA
    Posts
    17

    Unanswered: How do you trap an error when opening a form?

    (Access 2003) I keep getting errors when opening a form that is filtered to find a specific record/account number and when the record/account number isn't entered yet. I used the wizard to "Open a Form" - (with specific information to find). When the button is clicked an error message:
    Syntax error (missing operator) in query expression '[AccountNo]='1234-123".

    I want to trap this error and cause the form to open and add a new record (utilizing the account number in the new record) when ever this condition occurrs, or display a message on the screen "Account Number 1234-123 Not found - Do you want to add it?".

    Can this happen in the command button click event?

  2. #2
    Join Date
    Mar 2006
    Posts
    163
    Aren't you missing a closing single quote?

  3. #3
    Join Date
    Oct 2006
    Location
    New Kensington, PA
    Posts
    17
    As I stated before, I let the wizard create the filter when it asked if I wanted to open the form to find specific data. I saw that the error message did not look like the filter call and was wondering if this is a bug in Access error processing? However, the VBA code for the button looks correct:

    Private Sub cmdOpenContractForm_Click()
    On Error GoTo Err_cmdOpenContractForm_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmContractInformation"

    stLinkCriteria = "[AccountNo]=" & "'" & Me![AccountNo] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdOpenContractForm_Click:
    Exit Sub

    Err_cmdOpenContractForm_Click:
    MsgBox Err.Description
    Resume Exit_cmdOpenContractForm_Click

    End Sub

  4. #4
    Join Date
    Jul 2006
    Posts
    108
    there may have been a data "lag" in your computer that caused access to screw up, kinda like when you kick your computer and your burning CD, there are errors on the cd.

    put this in your button form:
    if it doesnt work, delete the button and run the wizard agian


    Private Sub cmdOpenContractForm_Click()
    On Error GoTo Err_cmdOpenContractForm_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmContractInformation"

    stLinkCriteria = "[AccountNo]=" & "'" & Me![AccountNo] & "''" 'added single
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdOpenContractForm_Click:
    Exit Sub

    Err_cmdOpenContractForm_Click:
    MsgBox Err.Description
    Resume Exit_cmdOpenContractForm_Click

    End Sub

Posting Permissions

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