Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fields visible depending on state of checkbox 1

Status
Not open for further replies.

thefourthwall

IS-IT--Management
Feb 26, 2002
387
US
Hello,

I created a form from a select query. The query is based on data inputted from equipment being dropped off for repair. One of the controls on the drop off form is a checkbox labeled "Data 911"

Now on a query-based form, I am trying to show fields only when that Data 911 checkbox displays as already checked but the results are not what I expected.

What is wrong with my code?
Code:
Private Sub Data_911_AfterUpdate()
If Me.Data_911 = True Then
    Me.Arrive_via_Relay.Visible = True
    Me.Sent_via_Relay.Visible = True
    Me.Contact_Last_Name.Visible = True
    Me.Contact_First_Name.Visible = True
    Me.ContactTZS.Visible = True
    Me.User_Rank.Visible = True
    Me.Heat_Ticket_Number.Visible = True
    Me.Date_Dropped_Off.Visible = True
    Me.Date_Picked_Up.Visible = True
    Me.TechSigningIn.Visible = True
    Me.TechSigningOut.Visible = True
Else
If Me.Data_911 = False Then
    Me.Arrive_via_Relay.Visible = False
    Me.Sent_via_Relay.Visible = False
    Me.Contact_Last_Name.Visible = False
    Me.Contact_First_Name.Visible = False
    Me.ContactTZS.Visible = False
    Me.User_Rank.Visible = False
    Me.Heat_Ticket_Number.Visible = False
    Me.Date_Dropped_Off.Visible = False
    Me.Date_Picked_Up.Visible = False
    Me.TechSigningIn.Visible = False
    Me.TechSigningOut.Visible = False

End If
End If
End Sub
and for the On_Open event of the form, I have
Code:
Private Sub Form_Open(Cancel As Integer)

    Me.Arrive_via_Relay.Visible = False
    Me.Sent_via_Relay.Visible = False
    Me.Contact_Last_Name.Visible = False
    Me.Contact_First_Name.Visible = False
    Me.ContactTZS.Visible = False
    Me.User_Rank.Visible = False
    Me.Heat_Ticket_Number.Visible = False
    Me.Date_Dropped_Off.Visible = False
    Me.Date_Picked_Up.Visible = False
    Me.TechSigningIn.Visible = False
    Me.TechSigningOut.Visible = False

End Sub
 
In the Current event procedure of the form and the AfterUpdate event of Data 911:
Code:
    Me!Arrive_via_Relay.Visible = Me![Data 911]
    Me!Sent_via_Relay.Visible = Me![Data 911]
    Me!Contact_Last_Name.Visible = Me![Data 911]
    Me!Contact_First_Name.Visible = Me![Data 911]
    Me!ContactTZS.Visible = Me![Data 911]
    Me!User_Rank.Visible = Me![Data 911]
    Me!Heat_Ticket_Number.Visible = Me![Data 911]
    Me!Date_Dropped_Off.Visible = Me![Data 911]
    Me!Date_Picked_Up.Visible = Me![Data 911]
    Me!TechSigningIn.Visible = Me![Data 911]
    Me!TechSigningOut.Visible = Me![Data 911]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV!

That structure had never occurred to me - and it works great.

Are you able to help with a different issue I'm having with a combo box on a different form?

Thanks,
thefourthwall
 
How are ya thefourthwall . . .

Use the [blue]On Load[/blue] event, instead of [blue]On Open[/blue]. Since you need hide/unhide from different places, you need a common routine. So perform the following:
[ol][li]Put a question mark [purple]?[/purple] in the [blue]Tag[/blue] property of the hidden controls ([red]no quotations please![[/red]).[/li]
[li]Copy/paste the following routine to the forms code module:
Code:
[blue]Public Sub ctlVis(Optional Hide)
   Dim ctl As Control, flg As Boolean
   
   If IsMissing(Hide) Then
      flg = Me.Data_911
   Else
      flg = Hide
   End If
   
   For Each ctl In Me.Controls
      If ctl.tag = "?" Then ctl.Visible = flg
   Next

End Sub[/blue]
[/li]
[li][blue]On Load[/blue] event should be:
Code:
[blue]   Call ctlVis(False)[/blue]
[/li]
[li][blue]Data_911_AfterUpdate[/blue] event should be:
Code:
[blue]   Call ctlVis[/blue]
[/li]
[li]Save and perform your testing ...[/li][/ol]


See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top