Help Modifying a piece of VBA (1 Viewer)

dale_j1992

Registered User.
Local time
Today, 17:27
Joined
Sep 23, 2016
Messages
26
Morning All :),

I Hope everyone is well.

I am still fairly new to access, and not a frequent user so go steady on me please.:eek:

With a current database i have this piece of VBA code that checks a barcode has been entered on the previous station/table before you can scan in on the current station.

We now however have a certain part number that doesn't get scanned at a station is there a way to edit the code below to achieve this.

Private Sub TxtBarInp_BeforeUpdate(Cancel As Integer)

Dim Answer As Variant

Answer = DLookup("[BARCODE]", "tbllogGEARCUTTING", "[BARCODE] = '" & TxtBarInp & "'")

If IsNull(Answer) Then
MsgBox "CRANKSHAFT HAS NOT BEEN SIGNED OFF AT GEARCUTTING CELL" & vbCrLf & "Please Contact your T.LEADER.", vbCritical + vbOKOnly + vbDefaultButton1, "Duplicate"

Cancel = True
Me.TxtBarInp.Undo


End If
End Sub

The Barcode we are scanning is 12 digit 110007312345, the first 7 digits are the part number and the following 5 the unique identifier.
its the 1100073 part number that i want the code to exclude from the check on this station.

Many thanks in advance for any help.

Kind regards

Dale :D
 

Minty

AWF VIP
Local time
Today, 17:27
Joined
Jul 26, 2013
Messages
10,368
You can use the Left() function to extract the first 7 characters, so something like
Code:
If Left(Me.TxtBarInp ,7) = "1100073" Then Exit Sub

Run before your DLookup() should suffice.
 

dale_j1992

Registered User.
Local time
Today, 17:27
Joined
Sep 23, 2016
Messages
26
Morning Minty :)

Firstly many thanks for your reply.

This method worked great, however i have just thought i can secure the process much better with a small adjustment. i just think i have a few issues with way i am laying the code out.

Private Sub TxtBarInp_BeforeUpdate(Cancel As Integer)

If Left(Me.TxtBarInp, 7) = "1100073" Then

Dim Answer As Variant

Answer = DLookup("[BARCODE]", "tbllogBALANCING", "[BARCODE] = '" & TxtBarInp & "'")

If IsNull(Answer) Then
MsgBox "CRANKSHAFT HAS NOT BEEN SIGNED OFF AT BALANCING CELL" & vbCrLf & "Please Contact your T.LEADER.", vbCritical + vbOKOnly + vbDefaultButton1, "Duplicate"

Cancel = True
Me.TxtBarInp.Undo

End If

Else

Dim Answer As Variant

Answer = DLookup("[BARCODE]", "tbllogGEARCUTTING", "[BARCODE] = '" & TxtBarInp & "'")

If IsNull(Answer) Then
MsgBox "CRANKSHAFT HAS NOT BEEN SIGNED OFF AT GEARCUTTING CELL" & vbCrLf & "Please Contact your T.LEADER.", vbCritical + vbOKOnly + vbDefaultButton1, "Duplicate"

Cancel = True
Me.TxtBarInp.Undo


End If
End If
End Sub

I thought this code would ensure the part was scanned on the previous station, but if the part number was 1100073 it would check the part was scanned on the station 2 previous.

Any pointers?

Cheers :cool:
 

dale_j1992

Registered User.
Local time
Today, 17:27
Joined
Sep 23, 2016
Messages
26
Morning Isladogs,

I apologise, having read the link i fully understand what you mean.

Sorry for any issues my cross posting has caused, i was just being a little naive hoping to get help quicker.

Kind regards
 

isladogs

MVP / VIP
Local time
Today, 17:27
Joined
Jan 14, 2017
Messages
18,209
No problems. Common mistake for new members.
Several of us look on multiple forums but not everyone does so
 

Users who are viewing this thread

Top Bottom