How do I make field controlled by a combo box remain on screen?

R

RemySS

I am creating a database that has a combo box listing 5 values. When either
value is selected, its corresponding fields become visible on screen (done
using VB).

However, when the database is closed and re-opened, the combo box value
remains, but the corresponding fields do not appear. The value in the combo
box then has to be reselected to make the fields appear.

This happens everytime, does anyone know some code that will remember what
has to remain on screen?

Thanks in advance!
 
W

Wayne Morgan

You need to add the code that hides/unhides the textboxes to the form's
Current event also. This will cause the correct textbox to be displayed as
you move from record to record, including moving to the first record as the
form opens.
 
R

RemySS

Thanks Wayne, that kind of answers the question except I't was a bit vague, I
haven't got a lot of experience with VB so would be mighty grateful if you
could elaborate a bit more on the process please.

Thanks!
 
W

Wayne Morgan

You apparently already have code in the combo box's AfterUpdate or Click
event to unhide the textbox you want. You need to copy this code to the
Current event of the form also. In addition to what you already have, you
may also need to hide the textboxes you don't want to see (i.e. the ones
displayed by the previous record).

Example:

Private Sub Form_Current()
If Me.cboMyCombo = "Rate" Then
Me.txtRate.Visible = True
Me.txtPrinciple.Visible = False
Me.txtLoanLength.Visible = False
End Sub
If Me.cboMyCombo = "Principle" Then
Me.txtRate.Visible = False
Me.txtPrinciple.Visible = True
Me.txtLoanLength.Visible = False
End Sub
If Me.cboMyCombo = "Loan Length" Then
Me.txtRate.Visible = False
Me.txtPrinciple.Visible = False
Me.txtLoanLength.Visible = True
End Sub

Adjust the names and values to match those of your controls.
 
R

RemySS

Thanks Wayne, got second time lucky! If i have anymore questions i'll be sure
to ask you.

Thanks
 
Top