473,657 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "afterupdat e action" I get the error mentioned above on the
assignment statement to [cboDogs].

Here's the failing function:
Private Sub dogregnbr_After Update()
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 1600
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

"DatePart(""yyy y"", 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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQlw9lYechKq OuFEgEQJgVQCg9/1mnAzbMHSxILH9P mmgOyxaLAMAn1I4
6Ht2+YZoaIHjE1f 37tfFjbCl
=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 "afterupdat e action" I get the error mentioned above on the
assignment statement to [cboDogs].

Here's the failing function:
Private Sub dogregnbr_After Update()
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
3160
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 Question ----------- I am looking for a list of popular compilers and/or platforms that *do not* support native C++ exceptions. Any pointers in this
0
1485
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 Public Sub New()
8
5463
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
3
1930
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 to attributes in tags (think Style tag -> Style object). The problem that I am chasing is: Html side:
0
1169
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 permissions as i read in some article but this didn't help to so i disable the JIT from the IDE properties and then i got those errors . please advice.
2
6319
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. I wrote a whole application. After completion I added a setup project. The setup project builds fine. But when I try to install the application, it gives me an error saying "This setup requires .NET framework." (Please install it). I checked the...
0
2532
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 pinvoking some C++ code, which was working also fine before. I wonder if these warning are causing the problem. I would appreciate some help or suggestions on how to correct these. Thanks. Warning 37 At least one of the arguments for...
4
2616
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 strange thing is that until the page is refreshed with Internet Explorer, the error keeps occurring. I realize no one can debug an application that I can't even provide details about (I didn't write nor do I have access to it) but what difference...
0
8397
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.