Results 1 to 4 of 4
  1. #1
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128

    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

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    "Doesn't work" means what? What is error message?

    Nothing wrong with the command. Post the SQL statement of the query for analysis.

    An alternative to opening SQL action query object is to run SQL action statement in VBA with CurrentDb.Execute method.

    What exactly is the "Transfer" query doing?

    Advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    I am getting Error no 7874 Microsoft Access can't find the object
    SQL Statement is

    DELETE [P Log].ExRefNumFROM [P Log]
    WHERE ((([P Log].ExRefNum)="ST-" & Format([Forms]![Condition]![TagID],"0000000")));

    So what my whole code is doing is when I make an update in form to a record it delete that record in backend and replace with the new one

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Why are you deleting a record when data needs to be edited? Just edit the record.

    The SQL needs a space in front of FROM. Since DELETE removes entire record, there is no need to specify field.

    DELETE FROM [P Log] WHERE ...
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Just doesn't seem to work!
    By txmmoore in forum Reports
    Replies: 9
    Last Post: 01-16-2014, 11:39 AM
  2. My query code doesn't work
    By blacksaibot in forum Programming
    Replies: 2
    Last Post: 03-08-2012, 02:59 PM
  3. Parameter Query doesn't work
    By Kimmie in forum Access
    Replies: 5
    Last Post: 10-07-2010, 01:30 PM
  4. Query doesn't work the day after
    By sithis876 in forum Queries
    Replies: 1
    Last Post: 07-13-2010, 07:11 AM
  5. Query doesn't work when launched by code
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-24-2009, 09:52 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