Link to home
Start Free TrialLog in
Avatar of dj88
dj88Flag for United States of America

asked on

MS Access - SQL - "Syntax Error in FROM Clause"

I'm using Microsoft Access 2003.  I have a form with a button.  When I click the button I want to find a particular record and then delete it.  I started with an ADODB Recordset open function using a select * from myTable where....  However, I had a syntax error.  To try to eliminate my syntax problem, I removed the where clause, and simply using a select * from myTable.  However, I'm still getting the error.  The code is below.  Since I'm trying to get the base SQL statement to work, I've commented out the delete command.

I have verified that I have a table named PropertyWorkOrder_JunctionTable in my database.  I've also tried encasing my table name with brackets, but that didn't help either.
Private Sub RemoveFromWOBtn_Click()
   On Error GoTo RemoveFromWOBtn_Click_Err
   Dim rst As New ADODB.Recordset
   Dim CurDB As Database
   
   Set CurDB = CurrentDb
     
   Set rst = New ADODB.Recordset
   rst.CursorType = adOpenDynamic
   rst.LockType = adLockOptimistic
   
   rst.Open "SELECT * FROM PropertyWorkOrder_JunctionTable", CurrentProject.Connection, , , adCmdTable
   'rst.Open "SELECT * FROM PropertyWorkOrder_JunctionTable WHERE [WorkOrderID] = '" & _
   '          Forms!WO_Mainform!WorkOrderID & "'" & " AND [PropertyID] = '" & _
   '          Forms!RemovePropertyForm!PropertyID & "'", CurrentProject.Connection, , , adCmdTable
   'With rst
        '.Delete
   'End With
   rst.Close

   DoCmd.Close acForm, "RemovePropertyForm", acSaveYes
     
RemoveFromWOBtn_Click_Exit:
    Exit Sub
RemoveFromWOBtn_Click_Err:
    MsgBox Err.Description
    Resume RemoveFromWOBtn_Click_Exit

End Sub

ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dj88

ASKER

Removing everything past the CurrentProject.Connection worked like a charm.  Since the SQL error kept coming up, I didn't think to check any of the other "Open" arguments.  Thanks.