Forum Discussion

BrianC42's avatar
BrianC42
Copper Contributor
Mar 14, 2024

Populate a field based off partial information in another field

So, I know a few people have posted about something similar, but I have a weird twist to throw into it.

I'm building a database to assist us with radio check-out/check-in for events we throw.  Currently we rent the radios when we need them, so the info for these radios change at each event.  But, they all have a barcode, and each type of device has a similar barcode.  Radios have an AXXX number (where X could be any number from 0 - 9), the batteries have an BAXXX number, etc.

When I'm adding the info for these items into the database, I'm going to have at least two fields, "barcode" and "item type".  What I would love to happen is when is that the item type field auto populates off the barcode field.  So if I type in A0013, item type automatically changes to radio.  But, it also needs to happen if I do A0042, A0302, etc.  Basically, any barcode that starts with A, I want it to change item type to battery.  If I put in BA032, BA013, or BA242 will change it to battery. Is that possible to do, or am I hoping for something that can't be done.

  • Woldman's avatar
    Woldman
    Iron Contributor

    Hi BrianC42 

     

    I've attached an example Access database that addresses your question. It contains a sample form with a barcode and type field. If you enter a barcode starting with an "A" the type field changes to "Radio" and likewise to "Battery" when you enter a barcode starting with a "B".

     

    The type field filling works with this little VBA code for the form:

     

     

    Private Sub txtBarcode_KeyUp(KeyCode As Integer, Shift As Integer)
        Select Case UCase(Mid(txtBarcode.Text, 1, 1))
        Case "A"
            txtType.Value = "Radio"
        Case "B"
            txtType.Value = "Battery"
        Case Else
            txtType.Value = ""
        End Select
    End Sub

     

     

    It's just a simple implementation, but I hope this helps,

     

    Tieme

Resources