Run-Time error '2001':You cancelled the previous operation. (1 Viewer)

accesser

Registered User.
Local time
Today, 01:56
Joined
Mar 17, 2003
Messages
54
I don't know why this error message appear.
this message appear when I a lookup function is run.
The code statement that genrate this error for me is:

CName = DLookup("Name", "VisCardHolders", "Indx=" & CIndx)

Dim CIndx as long
CIndx=50025

The VisCardholders is a recordset consists of two fields:
CIndx
Name

One of the exist records in the [VisCardholders] is
CIndx=50025
Name: James Southern


.I tried to find the reason of this error but unfortuantelly, I found nothing.
Please tell me.
 

KeithIT

Registered User.
Local time
Yesterday, 20:56
Joined
Dec 20, 2004
Messages
133
Where is that line in the code? What event are you using to trigger this code?
 

accesser

Registered User.
Local time
Today, 01:56
Joined
Mar 17, 2003
Messages
54
I am using the timer event

Private Sub Form_Timer()
CName = DLookup("Name", "VisCardholders", "Indx=" & CIndx)
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:56
Joined
Feb 19, 2002
Messages
43,266
Name is the name of a VBA property. Using property or function names as data names invariably causes problems with VBA. Try surronding Name with square brackets.

CName = DLookup("[Name]", "VisCardholders", "Indx=" & CIndx)

If that doesn't work, replace name with the name of some other field in the query/table. If that works, you have your answer - you'll need to change the name of Name to something else.
 

bretdunlap

Registered User.
Local time
Yesterday, 17:56
Joined
Nov 15, 2011
Messages
54
CName = DLookup("[Name]", "VisCardholders", "'Indx= CIndx'")

I had a similar problem this fixed my issue I think it has to do with the long
 

boblarson

Smeghead
Local time
Yesterday, 17:56
Joined
Jan 12, 2001
Messages
32,059
That error is generated when a null us returned by the DLookup. Encapsulate the part on the right side of the equals sign with the NZ function.
 

bretdunlap

Registered User.
Local time
Yesterday, 17:56
Joined
Nov 15, 2011
Messages
54
For my own education are you saying "Indx=" & NZ(CIndx)
 

boblarson

Smeghead
Local time
Yesterday, 17:56
Joined
Jan 12, 2001
Messages
32,059
For my own education are you saying "Indx=" & NZ(CIndx)


No, like this:

CName = Nz(DLookup("[Name]", "VisCardHolders", "Indx=" & CIndx), vbNullstring)

But make sure to include the square brackets on NAME like Pat said.
 
Last edited:

Users who are viewing this thread

Top Bottom