Working with Event Procedures

Paul1100

Registered User.
Local time
Today, 15:15
Joined
May 4, 2013
Messages
17
Hi,
I am trying to run vba code when i enter data on a field in a form. i would like to do a dlookup and followed it by running an append query depending on the outcome of the dlookup. I not sure how to do this if i am in the wrong area please tell me my code is below:


Private Sub Product_ID_Enter()
Dim Answer As Variant
Dim Count As Integer
Answer = DLookup("[Product ID]", "Printed Serials Log", "[Product ID] = '" & Me.[Product ID] & "'")
If IsNull(Answer) Then
Count = 0
MsgBox "Could not locate [" & Me.[Product ID] & "]"
Else
Count = 1
MsgBox "FOUND [" & Me.[Product ID] & "] In Table as being printed before Reprints are not allowed"
If Count = 0 Then
DoCmd.RunSQL "INSERT INTO[Printed Serials Log]([Part Number],[Serial Num],Rev,[Product ID])SELECT[Run Query].PartNumber,[Run Query].[Serial Num],[Run Query].Rev,[Run Query].[Product ID]FROM [Run Query]"
Else
End If
End If
End Sub

please help,
Paul
 
Sounds like you want the after update event. The enter event fires when you enter the textbox (when it gets focus).
 
Thank you for your response but i also notice that in my code i had not ended my first if statement so i did by moving the end sub command before i started the second if and all seems to work now.

thanks,
Paul
 

Users who are viewing this thread

Back
Top Bottom