Change format of other fields based on combo selection

  • Thread starter khashid via AccessMonster.com
  • Start date
K

khashid via AccessMonster.com

Hi, I have this urgent question Any help would be appreciated.

I have two field on the form, A and B. Field A is Comb Box with options 1, 2

What I want is if a user selects option 1 I want field B format to be changed
to 0000-0000-0000-0000#;0;_


and if user selects 2 then Format of Field would be 0000-0000-0000-00000#;0;_


( The difference is only last set of zeros have 5 zeros)
 
B

BruceM

That looks like an input mask rather than a format. To change it after
selecting from the combo box you could do something like this in the combo
box After Update event (assuming there are just the two choices as you have
described:

If Me.ComboBoxName = "1" Then
Me.TextBoxName.InputMask = "0000-0000-0000-0000#;0;_"
Else
Me.TextBoxName.InputMask = "0000-0000-0000-00000#;0;_"
End If

You could do something similar for format.
 
K

khashid via AccessMonster.com

Awsome, It worked fine..actually I have more then one option but for the rest
its same. But just for the sake on knowledge what should i do if i had more
then 1 option and every option has to have a different input mask
That looks like an input mask rather than a format. To change it after
selecting from the combo box you could do something like this in the combo
box After Update event (assuming there are just the two choices as you have
described:

If Me.ComboBoxName = "1" Then
Me.TextBoxName.InputMask = "0000-0000-0000-0000#;0;_"
Else
Me.TextBoxName.InputMask = "0000-0000-0000-00000#;0;_"
End If

You could do something similar for format.
Hi, I have this urgent question Any help would be appreciated.
[quoted text clipped - 9 lines]
( The difference is only last set of zeros have 5 zeros)
 
B

BruceM

You could use ElseIf. With three options it would look something like this:

If Me.ComboBoxName = "1" Then
Me.TextBoxName.InputMask = "0000-0000-0000-0000#;0;_"
ElseIf Me.ComboBoxName = "2" Then
Me.TextBoxName.InputMask = "0000-0000-0000-00000#;0;_"
Else
Me.TextBoxName.InputMask = "0000-0000-0000-000000#;0;_"
End If

With four options you would repeat the ElseIf line and the one below that.

Select Case is another approach that can be simpler in some cases:

Select Case Me.ComboBoxName
Case "1"
Me.TextBoxName.InputMask = "0000-0000-0000-0000#;0;_"
Case "2"
Me.TextBoxName.InputMask = "0000-0000-0000-00000#;0;_"
Case Else
Me.TextBoxName.InputMask = "0000-0000-0000-000000#;0;_"
End Select

Either one could get unwieldy if there were more than about five choices,
but there are ways of tidying up in such situations.

BTW, I am assuming the combo box selection is text. If it was number you
wouldn't have the quotes around the value.

khashid via AccessMonster.com said:
Awsome, It worked fine..actually I have more then one option but for the
rest
its same. But just for the sake on knowledge what should i do if i had
more
then 1 option and every option has to have a different input mask
That looks like an input mask rather than a format. To change it after
selecting from the combo box you could do something like this in the combo
box After Update event (assuming there are just the two choices as you
have
described:

If Me.ComboBoxName = "1" Then
Me.TextBoxName.InputMask = "0000-0000-0000-0000#;0;_"
Else
Me.TextBoxName.InputMask = "0000-0000-0000-00000#;0;_"
End If

You could do something similar for format.
Hi, I have this urgent question Any help would be appreciated.
[quoted text clipped - 9 lines]
( The difference is only last set of zeros have 5 zeros)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top