I am trying to create a Public Function unsuccessfully. I am converting parts of my database to allow barcode scanning into textboxes. Most companies that I receive bottles from the barcode matches the bottle number, but some have excess characters that I need to capture only a portion of the barcode. My form is Unbound and can add up to 12 records at a time (one case with 12 bottle each with a different barcode number). I added this code to the first bottle number textbox. This code works, but occurs 12 times on this form and about 30 times throughout the database, so I am trying to make a public function. I really don't know where to start since I don't know is how to capture the value of the current textbox without using its Name? The barcode scanner returns a carriage return after scanning and moves to the next field.
Any suggestions? Also suggestions for better code is also always appreciated.
You don't know what you don't know...
Code:
Private Sub txtUnit1_Exit(Cancel As Integer)
Dim intStyle As Integer
intStyle = Me.txtBCStyle 'autopopulates in form with a DLookup based on manufacturer combobox
If Len(txtUnit1.Value) > 0 Then
Select Case intStyle
Case 1 'leaves barcode as scanned
Exit Sub
Case 2 'keeps right 6 characters
txtUnit1.Value = Right(txtUnit1.Value, 6)
End Select
End If
End Sub
Any suggestions? Also suggestions for better code is also always appreciated.
You don't know what you don't know...