Question Input Mask is variable depending on another field. (1 Viewer)

Raynx

Registered User.
Local time
Today, 09:16
Joined
Sep 30, 2008
Messages
15
Hey, I need help with something.
I'm putting together a post office database, and the two most important fields for anything in this are "Tracking Number" and "Courier".
"Courier" is whichever mail delivery service brought the package to the post office, such as UPS, Fed-Ex, DHL, USPS, etc.
"Tracking Number" is a number which identifies a package, and follows a different format with each courier. For example:
UPS—starts with “1Z” and is 18 characters. The six digits following “1Z” can be either numeric or alpha-numeric, but the remaining characters after that are all numeric.
Ex. 1Z 333 3ZY 3847934748
So, here I am, entering data into the Tracking Number field, then tabbing over to the Courier field, when a thought comes to mind: I can use input masks to help make the Tracking Numbers follow the format style that each courier uses.
But, I can't think of how I can tell Access to do this.
IF the courier is UPS, THEN the Input Mask for that one particular Tracking Number field is...
IF the courier is Fed-Ex, THEN the Input Mask for that one particular Tracking Number field is...
So on and so forth.
Help me? Ideas? Advice? Thank you.
 

Banana

split with a cherry atop.
Local time
Today, 09:16
Joined
Sep 1, 2005
Messages
6,318
I had similar problem, and what I did was to use the first combobox to lookup the given value and used AfterUpdate event to alter the Input Mask. You can do that in VBA code as the textbox has InputMask property, which you can insert the rules and thus dynamically set input mask.
 

Raynx

Registered User.
Local time
Today, 09:16
Joined
Sep 30, 2008
Messages
15
Er, how would I do that? I'm not VBA savvy, particularly.
 

Banana

split with a cherry atop.
Local time
Today, 09:16
Joined
Sep 1, 2005
Messages
6,318
On the combobox where you specify courier, select "[Event Procedure]" for AfterUpdate property (on the Event tab on the property window). Then click the "..." button to the right to get to VBA.

The code would be something like this:

Code:
Private Sub CourierCombobox_AfterUpdate()

Case Select Me.CourierCombobox
    Case 1 'UPS was selected
    Me.TrackingTextBox.InputMask = "1Z" & chr(34) & "AAAAAA000000000000"
    Case 2 'Fed Ex
    Me.TrackingTextBox.InputMask = ...
    .... 'Repeat for all other carriers
    Case Else
      'You shouldn't be here...
End Select

End Sub

HTH.
 

Raynx

Registered User.
Local time
Today, 09:16
Joined
Sep 30, 2008
Messages
15
"You shouldn't be here..."?

And what does HTH mean?

Thank you, though. This does look like it work.
 

Banana

split with a cherry atop.
Local time
Today, 09:16
Joined
Sep 1, 2005
Messages
6,318
1) Case Else is for any other values, but since we're selecting from a combobox, it shouldn't give you any other value. But in case there's something wrong with it, you may want to place a code to warn that an invalid selection was made and to try again or something. Right now, the code will simply not set the input mask at all. It's up to you if you want to put in a messagebox, or do something else or nothing at all.

2) HTH = Hope that helps.

You are welcome. :)
 

Users who are viewing this thread

Top Bottom