0
votes

Keep getting a run-time error 3061 which the following script in Acces. Debugger reports a problem with last line but for the life of me I cannot see what the issue is. Any assistance greatly appreciated.

Dim db As Database

Dim salers As DAO.Recordset 'Sale

Set db = CurrentDb

Dim saleQuery As String

saleQuery = "SELECT * FROM Sales WHERE salesID = " & Me.saleID.Value & ";"

Set salers = db.OpenRecordset(saleQuery)
1
what datatype is salesID ?? Does salesID have a value? - Mitch Wheat
Use Debug.Print saleQuery to read the constructed SQL statement. - pteranodon
salesID is a Long Integer AutoNumber - Shane Wootton

1 Answers

0
votes

This error almost always means something is miss-spelled, or doesn't exist. So, ensure that Sales and salesID exist and are spelled properly in the query.

If that is OK, look at Me.saleID.Value. If this is a string, the query will have enclose the value in quotes:

saleQuery = "SELECT * FROM Sales WHERE salesID = '" & Me.saleID.Value & "';"

Note the ' around the saleID value.