rth
Jul 25 2005, 02:49 AM
I am attempting to use the After Update Event to lookup in the underlying table to see if this product is already listed in the table. Can anyone tell me what I'm doing wrong here.
I get a Run-time error '3464':
Data type mismatch in criteria expression.
Private Sub ProductBarCode_AfterUpdate()
If Not IsNull(DCount("ProductID", "Products", "ProductBarCode = " & Me.ProductBarCode)) Then
MsgBox "That product does not exist in the db"
Else
MsgBox "that product already exists in the db"
End If
Thanks!!!
freakazeud
Jul 25 2005, 02:55 AM
Hi,
try the following:
If DCount("ProductID", "Products", "ProductBarCode = " & Me.ProductBarCode) = 0 Then
MsgBox "That product does not exist in the db"
Else
MsgBox "that product already exists in the db"
End If
HTH
Good luck
rth
Jul 25 2005, 02:59 AM
HTH,
Thanks, I tried that and still get the same error.
Any ideas?
Thanks
MicroE
Jul 25 2005, 03:03 AM
Is ProductBarCode a text data yype? If so then use:
If DCount("ProductID", "Products", "ProductBarCode = '" & Me.ProductBarCode & "'") = 0 Then
freakazeud
Jul 25 2005, 03:04 AM
Hi,
What datatype is ProductBarCode?
BTW (by the way) my name it not HTH, it means Hope This/That Helps

.
HTH
Good luck
rth
Jul 25 2005, 03:09 AM
Thanks Matt. That was the problem.
And sorry freakazeud, didn't know about HTH...

btw, am I correct in using a text field for a UPC barcode field?
Thanks again
freakazeud
Jul 25 2005, 03:13 AM
you're welcome.
No problemo.
Glad WE could assist.
Yes you should use a Text field.
Good luck on future projects!
rth
Jul 25 2005, 03:35 AM
One other issue please,
The code works perfectly:
If DCount("ProductID", "Products", "ProductBarCode = '" & Me.ProductBarCode & "'") = 0 Then
'do nothing
Else
'cancel the entry, notify the user, and stay on the blank productbarcode field
MsgBox "A Product with that UPC is already in the database", , "Duplicate Record"
Me.Form.Undo
Me.ProductBarCode.SetFocus
End if
However, the last line doesn't seem to function (Setfocus) after the Message Box, the cursor is moved to the next field on the form. Why does it not go back to the productBarCode field?
Thanks!
MicroE
Jul 25 2005, 04:57 AM
Try:
docmd.GoToControl "ProductBarCode"
rth
Jul 25 2005, 05:31 AM
Thanks Matt,
Tried that and it too does not do it. Focus still goes to the next field.
MicroE
Jul 25 2005, 05:39 AM
Ah right, because the code is on the After Update Event. You will need to move the code to the Before Update Event and use Cancel = True.
CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("ProductID", "Products", "ProductBarCode = '" & Me!ProductBarCode.Value & "'") = 0 Then
'do nothing
Else
'cancel the entry, notify the user, and stay on the blank productbarcode field
MsgBox "A Product with that UPC is already in the database", , "Duplicate Record"
Cancel = True
End If
End Sub
rth
Jul 25 2005, 06:05 AM
Thanks Matt,
The After Update was the problem.
The Cancel = True statement caused a problem too...
I changed that line to
me.form.undo
and it's working as intended.
MANY thanks...
MicroE
Jul 25 2005, 07:34 AM
You are welcome.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.