UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> After Update Event Coding Problem    
 
   
rth
post 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!!!
Go to the top of the page
 
+
freakazeud
post 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
Go to the top of the page
 
+
rth
post 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
Go to the top of the page
 
+
MicroE
post 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
Go to the top of the page
 
+
freakazeud
post 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
Go to the top of the page
 
+
rth
post 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
Go to the top of the page
 
+
freakazeud
post 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!
Go to the top of the page
 
+
rth
post 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!
Go to the top of the page
 
+
MicroE
post Jul 25 2005, 04:57 AM
Post #9

UtterAccess VIP
Posts: 4,034
From: NY - USA



Try:
docmd.GoToControl "ProductBarCode"
Go to the top of the page
 
+
rth
post 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.
Go to the top of the page
 
+
MicroE
post 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
Go to the top of the page
 
+
rth
post 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...
Go to the top of the page
 
+
MicroE
post Jul 25 2005, 07:34 AM
Post #13

UtterAccess VIP
Posts: 4,034
From: NY - USA



You are welcome.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 21st May 2013 - 07:20 AM