473,394 Members | 1,889 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,394 software developers and data experts.

data type mismatch duplicates

Have this code to check for duplicates and if I change my BoxID to a text and run it as a string it works, but I need it to be a Long Integer. The data mismatch I am getting is underlined there are two. Thanks

Expand|Select|Wrap|Line Numbers
  1. Private Sub BoxID_AfterUpdate()
  2.  
  3. '*********************************
  4. 'Code sample courtesy of srfreeman
  5. '*********************************
  6.  
  7.     Dim BoxID As Integer
  8.     Dim stLinkCriteria As Integer
  9.     Dim rsc As DAO.Recordset
  10.  
  11.     Set rsc = Me.RecordsetClone
  12.  
  13.     BoxID = Me.BoxID.Value
  14.     stLinkCriteria = "[BoxID]=" & "'" & BoxID & "'"
  15.  
  16.     'Check CONTAINR table for duplicate BoxID
  17.     If DCount("BoxID", "CONTAINR", _
  18.               stLinkCriteria) > 0 Then        'Undo duplicate entry
  19.         Me.Undo
  20.         'Message box warning of duplication
  21.         MsgBox "Warning BoxID " _
  22.              & BoxID & " has already been entered." _
  23.              & vbCr & vbCr & "You will now been taken to the record.", _
  24.                vbInformation, "Duplicate Information"
  25.         'Go to record of original BoxID
  26.         rsc.FindFirst stLinkCriteria
  27.         Me.Bookmark = rsc.Bookmark
  28.     End If
  29.  
  30.     Set rsc = Nothing
  31. End Sub
  32.  
Feb 18 '10 #1
5 1430
Stewart Ross
2,545 Expert Mod 2GB
Hi. If your BoxID value is a long integer you don't need the single quotes on either side of the value in your stLinkCriteria where clause. The use of the single quotes sets the type of that value to Text, which I think will be the cause of your type mismatch.

Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[BoxID]=" & BoxID
-Stewart
Feb 18 '10 #2
I plugged that in and it didnt work and I though about what you said and I changed stLinkCriteria to string and left boxID as integer and it worked. Thanks so much, you saved me alot of time today.
Feb 18 '10 #3
for any future people that use this to check duplicates, change the boxID to a double and the table field to double, if you dont you get an error with over 6 numbers in field
Feb 19 '10 #4
Stewart Ross
2,545 Expert Mod 2GB
Hi again. Double is not the right choice for whole-number values; use Long instead. The range limitations for Integer and Long values are as follows (as listed in the MS Help information):

Integer 2 bytes -32,768 to 32,767
Long (long integer) 4 bytes -2,147,483,648 to 2,147,483,647
Double is good for working with non-whole number decimal values, but because of inherent limits to the precision of the way numbers are represented double-precision values may be subject to slight round-off errors that make them a poor choice for working with whole numbers. There is no such issue at all with Long integer values.

-Stewart
Feb 20 '10 #5
That makes sense, I will have to go back and change that. Thanks
Feb 23 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Santosh | last post by:
Since I just started my new work, I have inherited a MS Access database which has nearly 13000 records in a single table. Now, my mandate is to clean the database and maybe split the table into...
0
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
1
by: ArcadeJr | last post by:
Good morning all! I have been getting a Run-time Error message #3464 - Data Type mismatch in criteria expression. While trying to run a query. I have a database where the field Asset_Number...
3
by: Jake | last post by:
I am currently trying to create my own Point Of Sale software for my retail store. I wrote the program with the UPC field as Long integer. When I started to add the products by UPC code, I got a...
1
by: amitbadgi | last post by:
I am getting the following error while converting an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Data type mismatch in criteria expression. ...
5
by: RICHARD BROMBERG | last post by:
I am using Access 2000 .. I have a table called tblMembers with two fields MemID (Primary key indexed no duplicates) MemName (Thirty character text field) and I have a text box...
2
by: psychomad | last post by:
Please, can someone help me out to solve this error, i've been searching throughout my codes and yet i didnt succeed in finding the error!!!! The Error is: Server Error in '/' Application....
15
by: sara | last post by:
I have a Memo field in a table to hold notes from a conversation a social worker has had with a client (this is for a non-profit). If the user needs to update the memo field, I need to find the...
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
3
by: Mike Copeland | last post by:
How do I work with a std::list that might have multiple objects having the same "key", but which have other data that is different? Here's code that compiles, but doesn't do quite what I expect:...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
0
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...

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.