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
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