Use an Option Button on a Form to select an alternate Input Mask

Blue Karma

New User
Local time
Today, 09:35
Joined
Jun 30, 2006
Messages
5
I can create a customized Input Mask, however there are two possible structures that the data may take. I think that this should be doable by the use of two fields, if it can be done with one field it would be preferable for searching options. If I have to use two fields there would only be one or the other used for each record so I would prefer to have the unused field inhibited. Either way the code work is beyond my present ability, any assistance would be appreciated.
 
Why not use one field in your table to store the data. Let's say your form is called fmYourform and is bound to a table tblYourTable. The field that stores the information is called YourField.

On your form, place a textbox bound to YourField (txtYourField) and make it invisible. Add two unbound textboxes (txtFirstFormat and txtSecondFormat). Set the input mask for each textbox to the appropriate structure that you want.
Then, in the after_update event of each text box use code to set the value of txtYourField to be the same as the value you just types in.

eg. for txtFirstFormat
Code:
Private Sub txtFirstFormat_AfterUpdate()
if Me.txtFirstFormat & "" <> "" then Me.txtYourField = Me.txtFirstFormat
End sub

In the on_current event of your form, clear the values of the two unbound textboxes so that they are cleared for each record that you add.

eg,
Me.txtFirstFormat = ""
Me.txtSecondFormat = ""

If you want to use an option to make only one unbound textbox visible at a time, then use the after update event of the option or toggle button to make one textbox visible, and the other invisible, or vice versa depending on the value of the option/toggle button.

To make txtFirstFormat visible you would use something like:
Code:
If Me.YourOption = 0 then 
Me.txtFirstFormat.Visible = True
Me.txtSecondFormat.Visible = False
Else
Me.txtFirstFormat.Visible = False
Me.txtSecondFormat.Visible = True
End if
in the after_update event of your option or toggle button.

You might need to set the default visibility of the two boxes so that only one appears when you first open the form.
 

Users who are viewing this thread

Back
Top Bottom