473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Looking for help with Runtime Error

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 ***
Nov 13 '05 #1
5 1586
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Your use of DatePart() is incorrect. The correct usage is:

"DatePart(""yyyy"", regdt) = " & varYear

The interval needs 2 double quotes around it 'cuz it is inside another
pair of double quotes. Normally, it only requires a double qoute
delimiter.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQlw9lYechKqOuFEgEQJgVQCg9/1mnAzbMHSxILH9PmmgOyxaLAMAn1I4
6Ht2+YZoaIHjE1f37tfFjbCl
=o965
-----END PGP SIGNATURE-----

Susan Bricker wrote:
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 ***

Nov 13 '05 #2

Hi, MGFoster. Thanks for the suggestion. I hate to tell you, but I
made the change that you suggested and still got the same error at the
same location. Any other idea?
PLEASE! I'm starting to panic. Ok, maybe I overdramatize, here. But
I'm really stuck. Thanks.

Sueb

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #3
It looks like it's the DATEPART( ) portion of the criteria checking that
is failing.

I gave up on the DLOOKUP( ) and defined a DAO database and recordset.
Then I set a SQL string variable (strSQL) to the following SQL
statement:

strSQL = "SELECT * FROM tblDogs " & _
"WHERE [regnbr] = " & lngRegNo & " " & _
"AND DATEPART(""yyyy"",[regdt]) = " & varYear

and issued the db.opendataset(strSQL)
It still failed.

Then I changed the strSQL to:

strSQL = "SELECT * FROM tblDogs " & _
"WHERE [regnbr] = " & lngRegNo

and it worked.
So ... the question is how do I add the test for YEAR to the SQL
statement. I want to take the 2 digit year from the input Registration
Number and test the Registration Date in the tblDogs record and find a
match on REGNBR (long int) and REGYEAR.

Help!!

Thanks.

SueB
*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #4
Is my face RED!!! The problem was that the date field name in the
tblDogs record is NOT [regdt], it's [regstartdt]. So, datepart( ) does,
indeed work, when it has the correct syntax. : )

Sorry for taking up your time with this silly error. But thanks for
your help, anyway.

Sueb

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #5
rkc
Susan Bricker wrote:
Is my face RED!!! The problem was that the date field name in the
tblDogs record is NOT [regdt], it's [regstartdt]. So, datepart( ) does,
indeed work, when it has the correct syntax. : )

Sorry for taking up your time with this silly error. But thanks for
your help, anyway.


A good argument for using actual words for field names.
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bill Davidson | last post by:
Hi there, Please forgive me for posting this article on multiple groups. Being new in the newsgroups, I was not sure which group would have been appropriate for my question. Sorry. My...
0
by: Henrik Nordgren | last post by:
Im trying to build a simple chat app... here is the code: server visual basic code:-------------------------------------------------------------------------------- Public Class ChatServer ...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects...
0
by: Tiraman | last post by:
Hi , i m getting the following errors under the eventlog while i m trying to run some class that i wrote. at the first i got an error about the just-in-time : access denied and i added the...
2
by: asadikhan | last post by:
I had v1.0, v1.1 and v2.0 of .NET framework installed on my laptop and that was causing me a lot of grief. So I uninstalled v2.0 and pressed on with developing stuff in v1.0. Everything was great....
0
by: Pucca | last post by:
Hi I'm using vs2005. I am getting a bunch of compiler warnings after I made some changes to my code that was compiling clean. I'm also getting memory errors when I run my program and it's...
4
by: David | last post by:
I'm using the AxSHDocVw.WebBrowser control to download data from a webpage at work (it's an internal page on my company's intranet). The page produces a runtime error after a while and the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.