error 2001;canceled previous operation

  • Thread starter Thread starter Tammy
  • Start date Start date
T

Tammy

I am getting an error on a dlookup command. I have it in
use in other situations, but the last two times I have
tried to use it, I am getting this message: "you canceled
the previous operation" Run time error message 2001. I
have tried looking on the knowlege base and searching
questions on here with no luck!

Here is what I have for code (just one instance). Both
that are not working use variables for the criteria.

Dim strName As String
strName = Me![txtName]

Me![txtSOPid] = DLookup("[SOPid]", "tblMain", "[SOP_Name]
= """ & strName & """")
With CodeContextObject
DoCmd.GoToControl "txtSOPid"
DoCmd.FindRecord (.txtSOPsearch), acEntire, False, ,
False, acCurrent, True
End With

Me![cmdGetSOP].Visible = True
Me![cmdGetSOP].SetFocus

THANKS!
 
This error occurs if DLookup() is not able to evaluate its arguments, e.g.
if "tblMain" is not a table, or if "SOPid" and "SOP_Name" are not both
fields of that table. It may be as subtle as a number zero in place of an
upper case letter o.

To debug it, open the Immediate Window (Ctrl+G), and enter:
? DLookup("SOPid", "tblMain")
If that gives the same error, the problem is with one of those 2 names.

If that works, try:
? DLookup("SOPid", "tblMain", "SOP_Name = ""ZZZ""")
That should result in Null (unless SOP_Name really does have an entry ZZZ.)
 
I am now getting this message when trying to use a select
statement. I have double checked the fields to verify
there aren't typos and have even tried copying over sql
from a working query... any ideas??

varID = Me!lstSOPs.ItemData(varSelItem)
strSQL = "SELECT tblMain.* FROM tblMain WHERE
(((tblMain.SOPid)= """ & varID & """))"
DoCmd.OpenForm "RelatedEdit"
Forms!RelatedEdit.RecordSource = strSQL

I get the error on the "recordsource" line... and when I
highlight 'strSQL', it shows the select statement with
the correct id number in place of the 'varID' field.
But, I am getting the 2001 runtime error. I have taken
out the 'tblMain' portion; replaced the () around the
field with [] and several other things. HELP! THANKS!
-----Original Message-----
This error occurs if DLookup() is not able to evaluate its arguments, e.g.
if "tblMain" is not a table, or if "SOPid" and "SOP_Name" are not both
fields of that table. It may be as subtle as a number zero in place of an
upper case letter o.

To debug it, open the Immediate Window (Ctrl+G), and enter:
? DLookup("SOPid", "tblMain")
If that gives the same error, the problem is with one of those 2 names.

If that works, try:
? DLookup("SOPid", "tblMain", "SOP_Name = ""ZZZ""")
That should result in Null (unless SOP_Name really does have an entry ZZZ.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I am getting an error on a dlookup command. I have it in
use in other situations, but the last two times I have
tried to use it, I am getting this message: "you canceled
the previous operation" Run time error message 2001. I
have tried looking on the knowlege base and searching
questions on here with no luck!

Here is what I have for code (just one instance). Both
that are not working use variables for the criteria.

Dim strName As String
strName = Me![txtName]

Me![txtSOPid] = DLookup ("[SOPid]", "tblMain", "[SOP_Name]
= """ & strName & """")
With CodeContextObject
DoCmd.GoToControl "txtSOPid"
DoCmd.FindRecord (.txtSOPsearch), acEntire, False, ,
False, acCurrent, True
End With

Me![cmdGetSOP].Visible = True
Me![cmdGetSOP].SetFocus

THANKS!


.
 
Unless lstSOP is a multi-select listbox, you could just refer to its Value:
varID = Me!lstSOPs.Value

Presumably you have tried:
Debug.Print strSQL
and copied the output from the Immediate Window (ctrl+G) to SQL View of the
query. If that works, but the assignment to the RecordSource fails, error
2001 may indicate that the form is dirty and cannot be saved - i.e. Access
is saying that it cannot assign the RecordSource because the previous
operation (saving the existing record) did not work.

There are other reasons why the assignment may fail. For example, you will
run into trouble if some of the bound controls on the form are not
represented by the same names and/or data types in the new query. It may be
easier to use the WhereCondition of the OpenForm action:
strSQL = "SOPid = """ & Me.lstSOPs & """"
DoCmd.OpenForm "RelatedEdit", WhereCondition:=strSQL

Please note that if the field SOPid is a Number type field, you need to drop
the quotes.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Tammy said:
I am now getting this message when trying to use a select
statement. I have double checked the fields to verify
there aren't typos and have even tried copying over sql
from a working query... any ideas??

varID = Me!lstSOPs.ItemData(varSelItem)
strSQL = "SELECT tblMain.* FROM tblMain WHERE
(((tblMain.SOPid)= """ & varID & """))"
DoCmd.OpenForm "RelatedEdit"
Forms!RelatedEdit.RecordSource = strSQL

I get the error on the "recordsource" line... and when I
highlight 'strSQL', it shows the select statement with
the correct id number in place of the 'varID' field.
But, I am getting the 2001 runtime error. I have taken
out the 'tblMain' portion; replaced the () around the
field with [] and several other things. HELP! THANKS!
-----Original Message-----
This error occurs if DLookup() is not able to evaluate its arguments, e.g.
if "tblMain" is not a table, or if "SOPid" and "SOP_Name" are not both
fields of that table. It may be as subtle as a number zero in place of an
upper case letter o.

To debug it, open the Immediate Window (Ctrl+G), and enter:
? DLookup("SOPid", "tblMain")
If that gives the same error, the problem is with one of those 2 names.

If that works, try:
? DLookup("SOPid", "tblMain", "SOP_Name = ""ZZZ""")
That should result in Null (unless SOP_Name really does have an entry ZZZ.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I am getting an error on a dlookup command. I have it in
use in other situations, but the last two times I have
tried to use it, I am getting this message: "you canceled
the previous operation" Run time error message 2001. I
have tried looking on the knowlege base and searching
questions on here with no luck!

Here is what I have for code (just one instance). Both
that are not working use variables for the criteria.

Dim strName As String
strName = Me![txtName]

Me![txtSOPid] = DLookup ("[SOPid]", "tblMain", "[SOP_Name]
= """ & strName & """")
With CodeContextObject
DoCmd.GoToControl "txtSOPid"
DoCmd.FindRecord (.txtSOPsearch), acEntire, False, ,
False, acCurrent, True
End With

Me![cmdGetSOP].Visible = True
Me![cmdGetSOP].SetFocus

THANKS!
 
Back
Top