run time error 2001 - You canceled the previous operation

E

ecwhite

Hello, please i need help and I have been reading topics on this in the forum
but i stilll need help resolving my.

Under the click event of a button to insert a new record, i will like to
check if the an id number has already been entered in the database so i
display a message to let the user know b/c duplicate entry with same Id
number is not allowed. ID number is the primary key for each record for a
patient so it can't be autonumber.

Please read my comments in code

Private Sub cmd_insert_newpatient_rec_Click()
On Error GoTo Err_cmd_insert_newpatient_rec_Click
'On Error Resume Next - this fixes it but nothing else run

If DCount("[table1.id_nbr]", "q_duplicate_IDNo_lookup") >= 1 Then


Dim stIDNOFound_InDB As String
'Note : Macro1 is just a a MsgBox displaying that record using a particular
id number has already been entered in DB

stIDNOFound_InDB = "Macro1"
DoCmd.RunMacro stIDNOFound_InDB

Else

' This part below works perfectly without the DCOUNT part so i can insert
new records
Dim stDocName As String

stDocName = "Query1"
DoCmd.OpenQuery stDocName, acNormal, acEdit

stnewrecinserted = "open_frm_to_display_completed_msg"
DoCmd.OpenForm stnewrecinserted

End If
 
E

ecwhite

I have fixed this. I took me hours / days but if you ever have this problem,
lose the quotes like they said in other post. It took me a while to get how
it applies to my code but i got it. I changed it to

If DCount("[table1.id_nbr]", "q_duplicate_IDNo_lookup" = Me.id_nbr) >= 1 Then
 
D

Douglas J. Steele

I don't see how that could work, as it's invalid syntax.

The second parameter of DCount must be the name of a table or query.

"q_duplicate_IDNo_lookup" = Me.id_nbr is NOT the name of a table or query!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


ecwhite said:
I have fixed this. I took me hours / days but if you ever have this
problem,
lose the quotes like they said in other post. It took me a while to get
how
it applies to my code but i got it. I changed it to

If DCount("[table1.id_nbr]", "q_duplicate_IDNo_lookup" = Me.id_nbr) >= 1
Then

ecwhite said:
Hello, please i need help and I have been reading topics on this in the
forum
but i stilll need help resolving my.

Under the click event of a button to insert a new record, i will like to
check if the an id number has already been entered in the database so i
display a message to let the user know b/c duplicate entry with same Id
number is not allowed. ID number is the primary key for each record for a
patient so it can't be autonumber.

Please read my comments in code

Private Sub cmd_insert_newpatient_rec_Click()
On Error GoTo Err_cmd_insert_newpatient_rec_Click
'On Error Resume Next - this fixes it but nothing else run

If DCount("[table1.id_nbr]", "q_duplicate_IDNo_lookup") >= 1 Then


Dim stIDNOFound_InDB As String
'Note : Macro1 is just a a MsgBox displaying that record using a
particular
id number has already been entered in DB

stIDNOFound_InDB = "Macro1"
DoCmd.RunMacro stIDNOFound_InDB

Else

' This part below works perfectly without the DCOUNT part so i can insert
new records
Dim stDocName As String

stDocName = "Query1"
DoCmd.OpenQuery stDocName, acNormal, acEdit

stnewrecinserted = "open_frm_to_display_completed_msg"
DoCmd.OpenForm stnewrecinserted

End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top