autofill fields in the same form depending on whats in another field (1 Viewer)

dale_j1992

Registered User.
Local time
Today, 05:47
Joined
Sep 23, 2016
Messages
26
hello i asked this question before but from the answers I received i dont think i explained it very well. i have a table with the following headers Id, Barcode, part, Size, Date, Operator name. i have then set this up on a standard form, on opening the focus is set too the barcode field, the operator scans a barcode and this fills this field, the size field will be typed in depending on what size the operator measure the part at, the date is set as an autodate, and the operator name is automatically added from the user who is logged in. So coming back too the part field, i am trying to figure out a way of autofilling the part field depending on what barcode is scanned in the first field, the barcode is 12 digits long, the first 7 digits are part number for the batch of parts, the last 5 digits are the parts unique numer for example barcode:123456700056 this would be part 1234567 and the 56th part of this type, i have been prompted by another user to use the left() function to highlight only the first 7 digits that i require but i am stuck in writing a code that allows me for example, if the first 7 digits of the barcode are 1234567 then autofill field part as crankshaft or if the first 7 digits are 7654321 then autofill field part as camshaft. i hope someone can point me in the right direction with this i am fairly new too access and im pulling my hair out haha, many thanks in advance :)
 

Ranman256

Well-known member
Local time
Today, 00:47
Joined
Apr 9, 2015
Messages
4,337
In the form, in the barcode field propery, select the ON CHANGE event.
Click the ellipsis button at the right of the property,
Choose code,
Add the code:

Code:
Sub txtBarcode_onChange()
   TxtPart=left( txtBarcode,7)
End sub

Use the names of your text boxes,(not mine)
Or You can also put the LEFT command in the code where the barcode grabs info.
 

dale_j1992

Registered User.
Local time
Today, 05:47
Joined
Sep 23, 2016
Messages
26
thanks for the reply that code does work however all it does add the first 7 digits in to the part field, for example barcode 123456700056, will add 1234567 too the part field. Obviously i have parts that are linked too this number like 1234567 = crankshaft or 7654321 = Camshaft, i need to somehow modify your code so that the text Camshaft or Crankshaft is added too the part field instead of the part number itself, is there no way of coding if 1234567 then input crankshaft if 7654321 then input camshaft, obviously when i have new parts i will add them too the coding? thanks for your initial reply though it has moved me foward from where i was :)
 

Users who are viewing this thread

Top Bottom