Runtime Error 2001: You canceled the Previous operation

Y

Yblitzka

I have a form that pops up with a filter on it. It gets the filter setting
from another form that's already loaded.

frmOrder has a RefNum field that Me (the form I'm opening) uses as it's
OrderID field. I set up the filter on FormLoad.

The thing is, if the OrderID has nothing in tblOrderShip associated with it
yet, I need to open the form with a blank record, which it does fine, and it
needs to fill in the OrderID field. The easiest way I could think to do this
was with a DCount function. If DCount of a particular OrderID came up with
nothing, then I'd fill in the field and set the filter.

So I've gotten this far:

If DCount("[ErrorID]", "[tblOrderShip]", "[OrderID] = '" &
Forms![frmOrderEntry]![RefNum] & "'") = 0 Then (check DCount)
Me![OrderID] = Forms![frmOrderEntry]![RefNum] (set OID)
Me![ShipToPhone] = Now() (set another field)

Else
Me.Filter = "[OrderID] = " & Forms![frmOrderEntry]![RefNum] (set the filter)
Me.FilterOn = True

OrderID and RefNum are number fields, and I've tried the DCount with and
without the Forms![frmOrderEntry]![RefNum] in single quotes.

Any help?

~Yb

But I get the error in the title whenever I run the program - Previous
Operation canceled. I know this has something to do with the DCount in there,
but I can't figure it out.
 
D

Dirk Goldgar

Yblitzka said:
I have a form that pops up with a filter on it. It gets the filter
setting from another form that's already loaded.

frmOrder has a RefNum field that Me (the form I'm opening) uses as
it's OrderID field. I set up the filter on FormLoad.

The thing is, if the OrderID has nothing in tblOrderShip associated
with it yet, I need to open the form with a blank record, which it
does fine, and it needs to fill in the OrderID field. The easiest way
I could think to do this was with a DCount function. If DCount of a
particular OrderID came up with nothing, then I'd fill in the field
and set the filter.

So I've gotten this far:

If DCount("[ErrorID]", "[tblOrderShip]", "[OrderID] = '" &
Forms![frmOrderEntry]![RefNum] & "'") = 0 Then (check DCount)
Me![OrderID] = Forms![frmOrderEntry]![RefNum] (set OID)
Me![ShipToPhone] = Now() (set another field)

Else
Me.Filter = "[OrderID] = " & Forms![frmOrderEntry]![RefNum] (set the
filter) Me.FilterOn = True

OrderID and RefNum are number fields, and I've tried the DCount with
and without the Forms![frmOrderEntry]![RefNum] in single quotes.

Any help?

~Yb

But I get the error in the title whenever I run the program - Previous
Operation canceled. I know this has something to do with the DCount
in there, but I can't figure it out.

What's ErrorID? Is that a field in tblOrderShip? I'd have expected you
to use

If DCount("OrderID", "tblOrderShip", _
"OrderID = " & Forms![frmOrderEntry]![RefNum]) _
= 0
Then

assuming that OrderID is a numeric field. If it's a text field, then


If DCount("OrderID", "tblOrderShip", _
"OrderID = '" & Forms![frmOrderEntry]![RefNum] & "'") _
= 0
Then

Although in fact, this might be simpler, quicker, and work regardless of
the field type:

If IsNull(DLookup("OrderID", "tblOrderShip", _
"OrderID = Forms![frmOrderEntry]![RefNum]"))
Then

You can put the Forms reference inside the quotes and Access will still
resolve it.
 
Y

Yblitzka

:

Although in fact, this might be simpler, quicker, and work regardless of
the field type:

If IsNull(DLookup("OrderID", "tblOrderShip", _
"OrderID = Forms![frmOrderEntry]![RefNum]"))
Then

You can put the Forms reference inside the quotes and Access will still
resolve it.

Thanks, Dirk! The ISNull Statement worked perfectly!

~Yb
 

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