dj88
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_Junction Table 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_Junction Table", CurrentProject.Connection, , , adCmdTable
'rst.Open "SELECT * FROM PropertyWorkOrder_Junction Table WHERE [WorkOrderID] = '" & _
' Forms!WO_Mainform!WorkOrde rID & "'" & " AND [PropertyID] = '" & _
' Forms!RemovePropertyForm!P ropertyID & "'", 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
I have verified that I have a table named PropertyWorkOrder_Junction
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_Junction
'rst.Open "SELECT * FROM PropertyWorkOrder_Junction
' Forms!WO_Mainform!WorkOrde
' Forms!RemovePropertyForm!P
'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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER