My Assistant
![]() ![]() |
|
|
Jul 25 2005, 02:49 AM
Post
#1
|
|
|
UtterAccess Addict Posts: 241 |
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!!! |
|
|
|
Jul 25 2005, 02:55 AM
Post
#2
|
|
|
UtterAccess VIP Posts: 31,413 From: NC, USA |
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 |
|
|
|
Jul 25 2005, 02:59 AM
Post
#3
|
|
|
UtterAccess Addict Posts: 241 |
HTH,
Thanks, I tried that and still get the same error. Any ideas? Thanks |
|
|
|
Jul 25 2005, 03:03 AM
Post
#4
|
|
|
UtterAccess VIP Posts: 4,034 From: NY - USA |
Is ProductBarCode a text data yype? If so then use:
If DCount("ProductID", "Products", "ProductBarCode = '" & Me.ProductBarCode & "'") = 0 Then |
|
|
|
Jul 25 2005, 03:04 AM
Post
#5
|
|
|
UtterAccess VIP Posts: 31,413 From: NC, USA |
Hi,
What datatype is ProductBarCode? BTW (by the way) my name it not HTH, it means Hope This/That Helps (IMG:http://www.utteraccess.com/forum/style_emoticons/default/frown.gif) . HTH Good luck |
|
|
|
Jul 25 2005, 03:09 AM
Post
#6
|
|
|
UtterAccess Addict Posts: 241 |
Thanks Matt. That was the problem.
And sorry freakazeud, didn't know about HTH... (IMG:http://www.utteraccess.com/forum/style_emoticons/default/frown.gif) btw, am I correct in using a text field for a UPC barcode field? Thanks again |
|
|
|
Jul 25 2005, 03:13 AM
Post
#7
|
|
|
UtterAccess VIP Posts: 31,413 From: NC, USA |
you're welcome.
No problemo. Glad WE could assist. Yes you should use a Text field. Good luck on future projects! |
|
|
|
Jul 25 2005, 03:35 AM
Post
#8
|
|
|
UtterAccess Addict Posts: 241 |
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! |
|
|
|
Jul 25 2005, 04:57 AM
Post
#9
|
|
|
UtterAccess VIP Posts: 4,034 From: NY - USA |
Try:
docmd.GoToControl "ProductBarCode" |
|
|
|
Jul 25 2005, 05:31 AM
Post
#10
|
|
|
UtterAccess Addict Posts: 241 |
Thanks Matt,
Tried that and it too does not do it. Focus still goes to the next field. |
|
|
|
Jul 25 2005, 05:39 AM
Post
#11
|
|
|
UtterAccess VIP Posts: 4,034 From: NY - USA |
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 |
|
|
|
Jul 25 2005, 06:05 AM
Post
#12
|
|
|
UtterAccess Addict Posts: 241 |
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... |
|
|
|
Jul 25 2005, 07:34 AM
Post
#13
|
|
|
UtterAccess VIP Posts: 4,034 From: NY - USA |
You are welcome.
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 07:20 AM |