Results 1 to 7 of 7
  1. #1
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42

    Delete Syntax Issue

    I'm getting an error trying to run this code. See attached screenshot & code.


    Thanks,

    Click image for larger version. 

Name:	InValidUse.png 
Views:	9 
Size:	3.7 KB 
ID:	47339

    Dim strMsg As String Dim strCopy, strSQL As String
    Dim RST As Recordset




    DoCmd.RunSQL "DELETE * from tblEmployees WHERE EmpID=" & Me.EmpID
    strCopy = "INSERT Into tblDeletedEmployees SELECT tblEmployees. * from tblEmployees WHERE (tblEmployees.EmpID=" & Me.EmpID & ")"
    strSQL = "delete * from tblEmployees where EmpID = " & Me.EmpID
    DoCmd.RunSQL strCopy
    DoCmd.RunSQL strSQL


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why the same DELETE twice?

    There is a space between tblEmployees. and * in the INSERT sql. Don't need table prefix.

    strCopy = "INSERT Into tblDeletedEmployees SELECT * from tblEmployees WHERE (tblEmployees.EmpID=" & Me.EmpID & ")"
    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
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42
    Still getting an error. This is my corrected code.
    strCopy = "INSERT Into tblDeletedEmployees SELECT * from tblEmployees WHERE tblEmployees.EmpID=" & Me.EmpID & ""

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Syntax looks correct.

    Is there an autonumber field in tblDeletedEmployees.

    Why do you even have a tblDeletedEmployees? Why not just flag records as "Inactive"?
    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.

  5. #5
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42
    I mark records as deleted in tblAuditTrail and also need a copy in tblDeletedEmployees because of the details and for reports.
    No, there is no PK in the table but there is a number key not set to duplicates or anything.
    Click image for larger version. 

Name:	Syntax.png 
Views:	9 
Size:	4.0 KB 
ID:	47340
    Last edited by usfarang; 02-26-2022 at 01:59 AM. Reason: Picture or error

  6. #6
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42
    Ok, I simplified it and took your advice and set it to Inactive.
    Thanks,

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by usfarang View Post
    I mark records as deleted in tblAuditTrail and also need a copy in tblDeletedEmployees because of the details and for reports.
    No, there is no PK in the table but there is a number key not set to duplicates or anything.
    Click image for larger version. 

Name:	Syntax.png 
Views:	9 
Size:	4.0 KB 
ID:	47340
    Well that is telling you EmpID is empty?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Syntax issue with query
    By shank in forum Queries
    Replies: 19
    Last Post: 11-02-2019, 05:53 PM
  2. Simple Delete query syntax help needed.
    By Edward_ in forum Queries
    Replies: 5
    Last Post: 01-30-2018, 03:38 AM
  3. Syntax issue with Function
    By Cafe2UEMP in forum Programming
    Replies: 5
    Last Post: 12-27-2017, 01:14 PM
  4. Syntax Error when running delete SQL
    By TheKillerMonkey in forum Programming
    Replies: 3
    Last Post: 05-04-2016, 11:44 AM
  5. syntax issue when searchin dates
    By mike02 in forum Programming
    Replies: 1
    Last Post: 07-10-2013, 10:09 AM

Tags for this Thread

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