Hidden controls (1 Viewer)

Gismo

Registered User.
Local time
Today, 16:38
Joined
Jun 12, 2017
Messages
1,298
Hi,

I have a few controls hidden until a check box is selected.
works fine, obviously the controls are hidden when form opens until the check box is selected. my problem is now that when i open the form again, and the check box was selected on a previous session, the controls are still hidden but should now be visible because of the checkbox selected already. below is my code, how do I over come this to display when form opens to display hidden controls.

Private Sub EndCountry_Click()
If Me.EndCountry = False Then
Me.EndCountry1.Visible = True
Me.Enter.Visible = True
Me.Red.Visible = True
Refresh
Else
Me.EndCountry1.Visible = False
Me.Enter.Visible = False
Me.Red.Visible = False
Refresh
End If
End Sub
 

James Dickinson

PigeonPie
Local time
Tomorrow, 03:38
Joined
May 10, 2018
Messages
43
Hi,

when you select your checkbox do you store the boolean value in a table or global variable? Is it important that the next time you open this database you see you checkbox value again? If so then it should be stored in a table otherwise you can store your check box value in a global variable.

This can then be read the next time you open the form.

Code:
private sub For_Load()
     'GlOBAL VARIABLE
     ShowFields( gbShowFields)

     'TABLE VALUE
     ShowFields( dlookup("bShowFields","MyTableName"))
end sub

Private Sub ShowFields(bShow as boolean)
     Me.EndCountry1.Visible = bShow 
     Me.Enter.Visible = bShow 
     Me.Red.Visible = bShow 
End Sub
 

Minty

AWF VIP
Local time
Today, 14:38
Joined
Jul 26, 2013
Messages
10,355
You need to move or duplicate the code to the On_Current event of the form. And you can reduce that code to simply ;
Code:
Me.EndCountry1.Visible = Not  Me.EndCountry 
Me.Enter.Visible = Not  Me.EndCountry 
Me.Red.Visible = Not  Me.EndCountry 
Refresh
 

jdraw

Super Moderator
Staff member
Local time
Today, 10:38
Joined
Jan 23, 2006
Messages
15,364
Gismo,
Suggest you use code tags when posting code. When posting, highlight your code and then click the hash mark(octothorpe) in the header area.
Also, your code will be easier to read/follow with some indentation.
Code:
Private Sub EndCountry_Click()
    If Me.EndCountry = False Then
        Me.EndCountry1.Visible = True
        Me.Enter.Visible = True
        Me.Red.Visible = True
        Refresh
    Else
        Me.EndCountry1.Visible = False
        Me.Enter.Visible = False
        Me.Red.Visible = False
        Refresh
    End If
End Sub
 

Gismo

Registered User.
Local time
Today, 16:38
Joined
Jun 12, 2017
Messages
1,298
Yes i do save the selection in a table but did not go down that route to filter visibility.
with reference to above suggestion codes, I have some difficulty in understanding the Boolean code. I have desired to go with the code below but I think it is conflicting the outcome, only the End User Country is visible when End Country is deselected.

Code:
Private Sub Form_Load()
If Me.EndCountry = False Then
      Me.EndCountry1.Visible = True
      Me.Enter.Visible = True
      Me.Red.Visible = True
      Refresh
    Else
      Me.EndCountry1.Visible = False
      Me.Enter.Visible = False
      Me.Red.Visible = False
      Refresh
           End If
                  
  If Me.EndUser = False Then
      Me.EndUser1.Visible = True
      Me.Enter.Visible = True
      Me.Red.Visible = True
     Refresh
    Else
      Me.EndUser1.Visible = False
      Me.Enter.Visible = False
      Me.Red.Visible = False
      Refresh
           End If
End Sub
 

missinglinq

AWF VIP
Local time
Today, 10:38
Joined
Jun 20, 2003
Messages
6,423
You need to move or duplicate the code to the On_Current event of the form.

Everything else aside...you need to follow Minty's advice and place your code in the Form_Current event, as well as the EndCountry_Click event. Placing it in the Form_Load event, as you have in your last post, will only format the first Record displayed when the Form opens...it will not effect all Records.

Linq ;0)>
 

Gismo

Registered User.
Local time
Today, 16:38
Joined
Jun 12, 2017
Messages
1,298
works like a charm, thank you all :)
 

Minty

AWF VIP
Local time
Today, 14:38
Joined
Jul 26, 2013
Messages
10,355
Just to clarify the On_Current event usefulness - The Current event occurs when the focus moves to a record, making it the current record, or when the form is refreshed or requeried.

So as Linq said, even if you where to scroll back and forwards through your records the form controls would enable/disable appropriately.
 

missinglinq

AWF VIP
Local time
Today, 10:38
Joined
Jun 20, 2003
Messages
6,423
Glad we could help!

Good luck with your project!

Linq ;0)>
 

Users who are viewing this thread

Top Bottom