Results 1 to 3 of 3
  1. #1
    drunkenneo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    199

    Update Query functioning in second attempt

    I have written a code in VBA

    DoCmd.Save


    DoCmd.SetWarnings False
    DoCmd.RunSQL "DELETE Nz(table.tktNo," & Chr(34) & "" & Chr(34) & "), Nz(table.flightNo," & Chr(34) & "" & Chr(34) & "), Nz(table.dateofTravel," & Chr(34) & "" & Chr(34) & "), Nz(table.dest," & Chr(34) & "" & Chr(34) & "), Nz(table.origin," & Chr(34) & "" & Chr(34) & ") FROM table WHERE (((table.tktNo) Is Null) OR ((table.flightNo) Is Null) OR ((table.dateofTravel) Is Null) OR ((table.dest) Is Null) OR ((table.origin) Is Null) AND ((table.staffName) = " & Forms!frm_Main!Cmb_Staff & " ))"
    DoCmd.SetWarnings True
    DoCmd.Close

    When i press update after deleting some records it does not delete in forst Attempt, however it does in the second attempt. Please Help

  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,896
    DoCmd.Save does not save record, it saves the object and any changes that were made to its design such as altering property settings.
    Use DoCmd.RunCommand acCmdSaveRecord

    Don't need to specify fields in DELETE action because it is deleting the entire record. The table is actually named table? Is this code behind frm_Main? If so can use Me qualifier.

    CurrentDb.Execute "DELETE FROM table WHERE (tktNo Is Null Or flightNo Is Null Or dateofTravel Is Null Or dest Is Null Or origin Is Null) And staffName='" & Me.Cmb_Staff & "'"

    Won't need the SetWarnings lines.

    Really should use staff ID instead of staffName as criteria.

    Note the apostrophe delimiters for the combobox parameter. If the value of combobox is truly text (and not a number ID), need delimiters. If it is number ID then staffName is wrong field reference.
    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
    drunkenneo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    199
    It worked June7, was very helpfull

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

Similar Threads

  1. Control Wizard not functioning in reports
    By Harley Guy in forum Reports
    Replies: 2
    Last Post: 02-26-2013, 11:28 AM
  2. Combo Boxes Not Functioning
    By cdixon2098 in forum Forms
    Replies: 6
    Last Post: 08-27-2012, 02:51 PM
  3. After Update/concatenation not functioning
    By tariq1 in forum Programming
    Replies: 4
    Last Post: 08-19-2012, 11:54 AM
  4. After Insert macro not functioning
    By scottnew2ac in forum Access
    Replies: 2
    Last Post: 07-26-2012, 09:25 AM
  5. Runtime error not functioning A2007
    By gg80 in forum Programming
    Replies: 11
    Last Post: 09-04-2010, 01:24 PM

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