Visible problems

leerlap

Registered User.
Local time
Today, 06:08
Joined
May 4, 2003
Messages
22
I'm having difficulty figuring out to make certain fields visible based on user input. Here's a simplified example of what I'm trying to do:
I have two radio buttons that enter either a 1 or 2 in the variable [group]. There are two fields (that are linked to a table) on the form: [group1] and [group2]. So, if the user selects the radio button 1, then only [group1] would be visible on the screen - and if the user selects radio button 2, then only [group2] would be visible. Is there an easy way to do this? Thanks for your help.
Lee
 
One solution is as follows:

Private Sub YourFrame0_AfterUpdate()
Select Case Me!YourFrame0
Case 1
Me!txtGroup1.Visible = True
Me!txtGroup2.Visible = False
Case 2
Me!txtGroup1.Visible = False
Me!txtGroup2.Visible = True
End Select
End Sub

In the above example, two text boxes are involved.
 
I use this:

Set the tag property of the fields visibility you want to change to HideIt.
Create a module and add this code:

Function HideIt(FormName As String)
' This procedure will reverse the visability of any
' controls identified with Tag = "HideIt"

Dim F As Form, x As Integer
Set F = Forms(FormName)

For x = 0 To F.Count - 1
If F(x).Tag = "HideIt" Then
F(x).Visible = Not F(x).Visible
End If
Next x

End Function

In the On Current event of the form put code like this:

If Me.YourField = True Or Whatever Then
Call HideIt("YourFormNameHere")
End If

'Place the above code in the After Update event of the field that determines if the fields should be visible or not.

'Insert the correct name of your form and the correct name of your control that determines if the fields are visible or not.


You can use whatever tag you like to set the visible but this works well for 2 groups.


Hope it helps
Steve
 
Visibility issues continue

I finally had a few minutes to go back to figuring this issue out. Thank you llkhoutx and Indesisiv - i tried both of your suggestions and both worked to a point. However, i had trouble fully implementing them.

llkhoutx - i liked the simplicity of your approach, but when i did what you suggested, it set the text boxes visible/not visible for all records. How would I set it for each record?

Indesisiv - your approach was a bit more complicated, but makes sense with a lot of variables (which I have). However, I was a bit confused by your instructions. I created a module and put in the first set of instructions, and put the

If Me.YourField = True Or Whatever Then
Call HideIt("YourFormNameHere")
End If

in the afterupdate of the field determining visibility - i wasn't sure about putting it in the On Current event of the form though. Also, once i did everything, it would set the appropriate fields invisible when i selected the group1, but to make them visible, i had to select group 2 and then group 1 again. I want certain ones to be visible when i select group 1 and others visible when i select group 2. Any thoughts on how to proceed is appreciated.

Thanks again for your help - look forward to hearing from you (or anyone else) about this.

Lee
 
Use the Oncurrent event, ie chaing to a new record, to execute the same or similar code.
 
You could use the same module that is slightly modified.

Try:
Function HideAll(FormName As String, WhatToHide As String,WhatToShow As String)
' This procedure will reverse the visability of any
' controls identified with any tag you want.

Dim F As Form, x As Integer
Set F = Forms(FormName)

For x = 0 To F.Count - 1
If F(x).Tag = WhatToShow Then
F(x).Visible = true
End If
If F(x).Tag = WhatToHide Then
F(x).Visible = False
End If
Next x

End Function


Then on current use
Select Case Me.FrameWithRadioButtonsIn.Value

Case 1
Call HideAll("FormName", "Group2", "Group1")
Case 2
Call HideAll("FormName", "Group1", "Group2")
End Select

But you will need to use this in the on current aswell. eg Call form_current

Hope this helps you
Steve
 

Users who are viewing this thread

Back
Top Bottom