Results 1 to 4 of 4
  1. #1
    theosgood is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Location
    Denver, CO
    Posts
    30

    Delete in external database

    Hello,

    I have the following code

    If A then
    DoCmd.RunSQL "DELETE * FROM " & "[tblActive Offer Listing-" & strDept & "]" & "IN '" & strPathxpt & "'"
    else
    DoCmd.RunSQL "DELETE * FROM " & "[tblActive Offer Listing-" & strDept & "]" & " Where [tblActive Offer Listing-" & strDept & "].[Offer Number] <= 499 " & "IN '" & strPathxpt & "'"


    end if

    where strPathxpt is an external database: T:\Business Analysis\DataSource\AnalystTables-Footwear.mdb

    A works but when I add the <=499 condition I get the following error:

    In operator without () in query expression. I've tried adding () in a couple of places and no success. Any suggestions?

    Thanks

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    For debugging purposes, try this:

    Code:
    'Add this line
        Dim sSQL As String
    
        If A Then
            sSQL = "DELETE * FROM " & "[tblActive Offer Listing-" & strDept & "]" & "IN '" & strPathxpt & "'"
        Else
            sSQL = "DELETE * FROM " & "[tblActive Offer Listing-" & strDept & "]" & " Where [tblActive Offer Listing-" & strDept & "].[Offer Number] <= 499 " & "IN '" & strPathxpt & "'"
        End If
    
        Debug.Print sSQL
    'open the Immediate window (Ctrl-G) to view the SQL string to see if it is a valid string.
    
        DoCmd.RunSQL sSQL
    Post back with the results of the debug statement...


    --------------------------
    I don't use DoCmd.RunSQL because of the warnings that are displayed. To get rid of the warnings, you have to set warnings off, then remember to turn them back on.
    I use:
    CurrentDb.Execute sSQL, dbFailOnError

    The "dbFailOnError" will notify you if there is an error.

  3. #3
    theosgood is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Location
    Denver, CO
    Posts
    30
    Thanks Steve,

    I forgot to include the docmd.runsql in my example when I cut and pasted. However, I did find the solution a short time ago. It was in the syntax. I had the where clause in the wrong spot.

    DoCmd.RunSQL "Delete [tblActive Offer Listing-" & strDept & "].[Offer Number] FROM [tblActive Offer Listing-" & strDept & "] IN '" & strPathxpt & "' WHERE ((([tblActive Offer Listing-" & strDept & "].[Offer Number]) <= 499))"

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

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

Similar Threads

  1. Replies: 9
    Last Post: 10-05-2012, 06:15 AM
  2. Replies: 12
    Last Post: 10-20-2011, 08:22 AM
  3. Import individual records from external database
    By jimh in forum Import/Export Data
    Replies: 3
    Last Post: 09-13-2011, 04:19 PM
  4. Linked Database with 2 external Sources?
    By andersonEE in forum Import/Export Data
    Replies: 1
    Last Post: 07-16-2011, 05:52 PM
  5. Replies: 0
    Last Post: 09-18-2009, 07:33 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