Easy Q about visibility

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hello again. I would like to have a subform appear when the value in a text
box is less than 3. I have tried all the update events but still have no
success. I am using the following code

Private Sub txtTextBox_Change()
Dim intyears As Integer

intyears = txtAddressYears.Value ' have tried to do with and without this
line.

If intyears < 3 Then
sfrmSubform.Visible = True
Else
sfrmSubform.Visible = False
End If

Please help
 
Hi Chris,

The event you would want to use is the AfterUpdate event for the textbox and
also in the Current event of the form so that the subform is hidden when you
navigate to an existing record that meets the critera for hidding the
subform.

Here's the code to add:

me.sfrmSubform.Visible=me.txtAddressYears<3

Note that it is preferable to use the "Me" keyword when referring to
controls since this *clearly* establishes that the thing being referenced is
a control (or field) and not a vba variable. The "if" statement is replaced
by a single logical comparison, the result of which is assigned to the
boolean property. This is just a shortcut for the full "If-Then Else"
statement.
 
You dont need the variable.

in the afterupdate event of txtaddressyears try

IF me.txtaddressyears < 3 then
me.sfrmSubform.visible = true
else
me.sfrmSubform.visible = false
end if
 
Back
Top