Results 1 to 2 of 2
  1. #1
    Join Date
    May 2014
    Posts
    98

    Unanswered: Open Query doesn't work

    Dim MyCheck As Variant, MySQL As Variant, MyAnswer As Variant
    MySQL = BuildCriteria("ExRefNum", dbText, "ST-" & Format([Forms]![Condition]![TagID], "0000000"))
    MyCheck = DLookup("PID", "P Log", MySQL)

    If Not IsNull(MyCheck) Then
    MyAnswer = MsgBox("This Tag has already been added to the Priority Log!" & Chr(10) & Chr(13) & Chr(10) & Chr(13) & "Do you want to overwrite the record?", vbYesNo, "Record Found!")
    If MyAnswer = vbYes Then
    DoCmd.SetWarnings (False)

    DoCmd.OpenQuery "Delete Tags from P Log"
    DoCmd.OpenQuery "Transfer Tags to P Log"
    DoCmd.SetWarnings (True)
    MsgBox "This Tag has been added to the P Log", vbOKOnly, "Record Added"
    End If
    Else: DoCmd.SetWarnings (False)
    DoCmd.OpenQuery "Transfer Tags to P Log"
    DoCmd.SetWarnings (True)
    MsgBox "This Tag has been added to the P Log", vbOKOnly, "Record Added"
    End If

    DoCmd.GoToRecord , , acNewRec
    Exit_btn_Save_Click:
    Exit Sub
    Err_btn_Save_Click:
    MsgBox Err.Description
    Resume Exit_btn_Save_Click


    Please check what I am doing wrong in the code

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    If you are daft enough to use non standard characters in your column or table names then you must delimit them with square brackets.

    The reason you are not getting an error message is that you have cunningly turned off warnings before running a query with invalid syntax. Mere mortals would probably leave suppressing warnings till the code is proven to work. Less trusting developers shouldn't rely on such behaviour and in my books should trap for errors and handle appropriately
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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