Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 24th, 2004, 08:02 PM
Ericed Ericed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 6 Ericed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Check for Duplicate Values in a Field -

I wrote some code for a form to check for duplicate values in a field 'beforeupdate'. When it runs I keep getting an error "Data type mismatch in criteria expression". I cannot figure out why I'm recieving this error. The table is on SQL Server with a numeric datatype. The code is based on an article by Microsoft - ACC2000: How to Use Visual Basic for Applications to Check for Duplicate Values in a Field.

Does anybody have a suggestion to why this happening.

The code used is below:

Dim x As Variant

x = DLookup("[AssetTagNumber]", "tblAssets", "[AssetTagNumber]= '" _
& Forms!frmEditAssets!AssetTagNumber & "'")

On Error GoTo CustID_Err

If Not IsNull(x) Then
Beep
MsgBox "That value already exists", vbOKOnly, "Duplicate Value"
Cancel = True
End If

CustID_Exit:
Exit Sub

CustID_Err:
MsgBox Error$
Resume CustID_Exit


Reply With Quote
  #2  
Old November 29th, 2004, 02:16 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
Ericed,

Data type mismatch is due to a string criteria used in a numeric field. Change your criteria slightly,

Dim x As Variant
Dim i As Integer

i = Forms![frmEditAssets]![AssetTagNumber]
x = DLookup("[AssetTagNumber]", "tblAssets", "[AssetTagNumber]= " & i)



lwells

Reply With Quote
  #3  
Old February 18th, 2005, 07:16 AM
xpetex xpetex is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 56 xpetex User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 50 m 7 sec
Reputation Power: 4
what about if I am using normal querys to try and accomplish the same? Is there a way to do it like that too??

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Check for Duplicate Values in a Field -


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT