Run time error 2001

  • Thread starter sike11 via AccessMonster.com
  • Start date
S

sike11 via AccessMonster.com

Good morning all,

I have the following code in my BeforeUpdate and I keep getting the same
error: Run time error 2001 - You have cancelled the previous operation. I am
unsure as to what I have cancelled. Can someone please help me?

Private Sub txtQualref_BeforeUpdate(Cancel As Integer)
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

SID = Me.txtQualref.Value
stLinkCriteria = "me.txtQualref =" & "'" & SID & "'"

'Check tblQOEDescription for duplicate entries
If DCount("QoE-" & "me.txtQualref", "tblQOEDescription",
stLinkCriteria) > 0 Then
Me.Undo
'Message box warning of duplication
MsgBox "Warning This Control " & SID & " has already been
entered." & vbCr & vbCr & _
"You will now be taken to the record.", vbInformation,
"Duplicate Information"
'Go to record of original control
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub

Thanks in advance.

Mary.
 
A

Allen Browne

Mary, which line gives you the error?
Is it the line starting:
If DCount(...
If so, one of the arguments is incorrect.

Try this:
stLinkCriteria = "[MyField] = """ & Me.txtQualRef & """"
If DCount("*", "[MyTable]", stLinkCriteria) > 0 Then
...

Replace MyTable with the name of the table you are trying to count records
in.

Replace MyField with the name of the field in that table that should have
the value matching the text in txtQualRef.

DCount() takes the same arguments as DLookup(), so this article might help
explain how to make it work:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
 
S

sike11 via AccessMonster.com

Thank you Allen,

I will try it and let you know how it works out.

Mary.

Allen said:
Mary, which line gives you the error?
Is it the line starting:
If DCount(...
If so, one of the arguments is incorrect.

Try this:
stLinkCriteria = "[MyField] = """ & Me.txtQualRef & """"
If DCount("*", "[MyTable]", stLinkCriteria) > 0 Then
...

Replace MyTable with the name of the table you are trying to count records
in.

Replace MyField with the name of the field in that table that should have
the value matching the text in txtQualRef.

DCount() takes the same arguments as DLookup(), so this article might help
explain how to make it work:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
I have the following code in my BeforeUpdate and I keep getting the same
error: Run time error 2001 - You have cancelled the previous operation. I
[quoted text clipped - 26 lines]
Set rsc = Nothing
End Sub
 
S

sike11 via AccessMonster.com

Hi Allen,

Thank you so much!! It was the line starting "If DCount(...) that was causing
the problem. I tired your code and it worked great!!
Again, thank you.

Mary.

Allen said:
Mary, which line gives you the error?
Is it the line starting:
If DCount(...
If so, one of the arguments is incorrect.

Try this:
stLinkCriteria = "[MyField] = """ & Me.txtQualRef & """"
If DCount("*", "[MyTable]", stLinkCriteria) > 0 Then
...

Replace MyTable with the name of the table you are trying to count records
in.

Replace MyField with the name of the field in that table that should have
the value matching the text in txtQualRef.

DCount() takes the same arguments as DLookup(), so this article might help
explain how to make it work:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
I have the following code in my BeforeUpdate and I keep getting the same
error: Run time error 2001 - You have cancelled the previous operation. I
[quoted text clipped - 26 lines]
Set rsc = Nothing
End Sub
 

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