Greetings! Can you help me?
Here's the error:
“Run-time error ‘2001’. You canceled the previous operation.”
Here's the form description:
[frmDataEntry] has 2 controls involved with this error:
[dogregnbr] = unbound text box (expecting user to type in dog
registration number (format: yy-nnnn)
[cboDogs] = unbound combobox with three columns: 1=dogID (key to tblDogs
record) bound column and not displayed , 2=resultant of query displaying
DogFullname, DogCallName, DogOwnerName and 3=regnbr (not displayed)
The intent of the form:
User will either (1) type in known dog reg. nbr and the combobox will
display the dog info or (2) select a dog from the dropdown combobox and
the dog Registration number will be displayed in the text box.
Then the user will select a command button to display record for display
or update.
Problem: When a valid [dogregnbr] is typed in and the TAB key it hit to
force the "afterupdate action" I get the error mentioned above on the
assignment statement to [cboDogs].
Here's the failing function:
Private Sub dogregnbr_AfterUpdate()
Dim strRegDate As String
Dim strRegNo As String
Dim lngRegNo As Long
Dim dummydate As Date
Dim varYear As Variant
strRegDate = "01/01/20" & Left(dogregnbr, 2) 'dummy date
strRegNo = Right(dogregnbr, (Len(dogregnbr) - 3))
varYear = Year(strRegDate)
lngRegNo = CLng(strRegNo)
Me!cboDogs = DLookup("[dogID]", _
"tblDogs", _
"regnbr = '" & lngRegNo & "' AND " & _
"datepart([regdt],yyyy) = " & varYear)
End Sub
The statement that is failing is:
Me!cboDogs = DLookup("[dogID]", _
"tblDogs", _
"regnbr = '" & lngRegNo & "' AND " & _
"datepart([regdt],yyyy) = " & varYear)
Here's the background:
I have a table [tblDogs] with a the following fields:
registration number [regnbr] defined as a long int and registration date
[regstartdt] defined as a short date.
(tblDogs has lots of other fields, but they are not involved in this
problem ... I think)
I envision having [regnbr] defined as an integer in the table but the
real registration number (for display and for reports) is a text field
(string) having the following format: yy-nnnn, where yy=year and nnnn is
the integer in string format.
This is so that the data stored is reduced in size and the user will see
the yy-nnnn registration number.
Questions:
1. Why is the error occurring?
2. Is there a better way to do this?
Thanks, so much.
SueB
*** Sent via Developersdex http://www.developersdex.com ***