Base on text box from selection of another on form

  • Thread starter Thread starter slagg7575
  • Start date Start date
S

slagg7575

Hi All,

Easy question here, I have on text box called Smoking, and if NO, i
need textbox-Years Smoked to be 'NA' , otherwise, if YES, the user will
enter the rest of the data for years smoked. How is this done? Thanks!

Slagg
 
What is the data type of the table field bound to the Years Smoked text box?
It probably should be either an Interger or a Long. In this case, 'NA' would
not be accepted in the table. If it is not a number, then you may have a
problem using it in calculations.

I would not use a text box for a Yes/No answer. I would suggest a check
box. No reason for a user to have to type in a Yes or No and no reason for
you to have to validate that a good answer was typed in.

I would make all the controls related to smoking Locked in design view and
only unlock them if the Smoking check box is checked.

If you do this, don't forget to change the data type of the table field
bound to the Smoking check box from text to Boolean (Yes/No).

Now, to make it work, use the After Update event of the check box:

Private Sub chkSmoking_AfterUpdate()

With Me
If .chkSmoking = True Then
.[Years Smoked].Locked = False
.OtherControlsForSmoking.Locked = False
.[Years Smoked].SetFocus
Else
.[Years Smoked] = 0
End If
End With
End Sub

And to keep it in sync with current records, use the form's Current event:

With Me
If .chkSmoking = True Then
.[Years Smoked].Locked = True
.OtherControlsForSmoking.Locked = True
Else
.[Years Smoked].Locked = False
.OtherControlsForSmoking.Locked = False
End If
 

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

Back
Top