|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
what about if I am using normal querys to try and accomplish the same? Is there a way to do it like that too??
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Check for Duplicate Values in a Field - |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|