Error 2001 you cancelled previous operation

tezread

Registered User.
Local time
Today, 11:32
Joined
Jan 26, 2010
Messages
330
Run time Error 2001 you cancelled previous operation

Hi thereI am getting an error message 'error 2001 cancelled previous operation'It happens when I click an item in a list boxHer eis the codePrivate Sub LstCustomer_Click()Me.RecordSource = "SELECT * FROM tblPatient " & _ "WHERE PatientId=" & "'" & Me.LstCustomer & "'"End Sub
 
Last edited:
Put your SELECT statement in a string variable and then display it with a MsgBox. It will help get the syntax correct.
 
Put your SELECT statement in a string variable and then display it with a MsgBox. It will help get the syntax correct.

Hi RuralguyI got the sample code from another database. I notice the old database was using CustomerID and that primary key had a text property against it. My EpisodeID is an autonumber.I am it sure how to do what you say as VBA is my acheilles heel
 
This is what your post would have looked like if you had used the code tags:
Code:
Private Sub LstCustomer_Click()

   Me.RecordSource = "SELECT * FROM tblPatient " & _
                     "WHERE PatientId= " & "'" & Me.LstCustomer & "'"
                     
End Sub
That code expected PatientID to be a string value. If in fact it is an AutoNumber (Long) in your case then you drop the single quotes and it would look like this:
Code:
Private Sub LstCustomer_Click()

   Me.RecordSource = "SELECT * FROM tblPatient " & _
                     "WHERE PatientId= " & Me.LstCustomer 
                     
End Sub
 

Users who are viewing this thread

Back
Top Bottom