Enabled check box (1 Viewer)

iantaylor

New member
Local time
Today, 04:07
Joined
Oct 8, 2001
Messages
9
Hello.
I am to make a option visiable by changing it to enabled, Yes from No
I tried to use the build expression but it hasn't worked.

I'm afraid I know zero about VB so please give as much details as possible.

Thanks in advance
Ian
 

jstutz

Registered User.
Local time
Today, 04:07
Joined
Jan 28, 2000
Messages
80
In VBA you can set a control's properties from the same form using code like:

Me!ControlName.PropertyName = Value

In the case of settings a property to YES or NO in VBA, for YES you can use either vbYes or -1, and for NO you can use either vbNo or 0. I suggest using 0 or -1. So in your case, you would use something like:

me!YourControl.visible = 0 'makes it invisible
me!YourControl.visible = -1 'makes it visible

OR....

me!YourControl.Enabled = 0 'makes it un-enabled
me!YourControl.Enabled = -1 'makes it enabled

Hope this helps...
js
 

jstutz

Registered User.
Local time
Today, 04:07
Joined
Jan 28, 2000
Messages
80
Sorry... I just re-read your post... you need to use the following code in the AfterUpdate Event of your option box:

If me.optionboxname = -1 then
me!control.visible = -1
Else
me.!control.visible = 0
End if

js
 

iantaylor

New member
Local time
Today, 04:07
Joined
Oct 8, 2001
Messages
9
Hi jstutz,

Thanks for the help, from what you said I created the below.

Problem I found with this is that if you select the check box making the second part visible, when close and go back into the form the second option is hidden again.
I tried to get the programe to run when the form opens but this didn't work. do you have any suggestions?

Thanks
Ian


Private Sub Employed_AfterUpdate()
If Me!Employed = -1 Then 'if check is yes
Me!EmpPayslip.Visible = True
Me!Label17.Visible = True
Me!Label9.Visible = True
Me!Label10.Visible = True
ElseIf Me!Employed = 0 Then 'if check is no
Me!EmpPayslip.Visible = False
Me!Label17.Visible = False
Me!Label9.Visible = False
Me!Label10.Visible = False
End If
End Sub

Private Sub SelfEmployed_AfterUpdate()
If Me!SelfEmployed = -1 Then 'if check is yes
Me!SEmpPayslip.Visible = True
Me!Label18.Visible = True
Me!Label13.Visible = True
Me!Label14.Visible = True
ElseIf Me!SelfEmployed = 0 Then 'if check is no
Me!SEmpPayslip.Visible = False
Me!Label18.Visible = False
Me!Label13.Visible = False
Me!Label14.Visible = False
End If
End Sub
 

jstutz

Registered User.
Local time
Today, 04:07
Joined
Jan 28, 2000
Messages
80
If you copy the code from both of your AfterUpdate events and put them in the form's OnCurrent event, each time you switch to a new record, the code should run and hide or show the appropriate controls on your form. The code would look like:

----------------------------
Private Sub Form_Current()
If Me!Employed = -1 Then 'if check is yes
Me!EmpPayslip.Visible = True
Me!Label17.Visible = True
Me!Label9.Visible = True
Me!Label10.Visible = True
ElseIf Me!Employed = 0 Then 'if check is no
Me!EmpPayslip.Visible = False
Me!Label17.Visible = False
Me!Label9.Visible = False
Me!Label10.Visible = False
End If

If Me!SelfEmployed = -1 Then 'if check is yes
Me!SEmpPayslip.Visible = True
Me!Label18.Visible = True
Me!Label13.Visible = True
Me!Label14.Visible = True
ElseIf Me!SelfEmployed = 0 Then 'if check is no
Me!SEmpPayslip.Visible = False
Me!Label18.Visible = False
Me!Label13.Visible = False
Me!Label14.Visible = False
End If
End Sub
----------------------------
 

iantaylor

New member
Local time
Today, 04:07
Joined
Oct 8, 2001
Messages
9
Thanks JSTUTZ, this worked at treat.

One final thing I hope you can help me with.

Depending on which check box's are ticked depends on what questions are shown.
Even though this works great, there are gaps on the form where the questions not shown are.

Is there anyway of squashing the shown questions so that they are all together and so it looks tidier?

Thanks again for your help.
Ian Taylor
ian.taylor@cmm-group.com
 

iantaylor

New member
Local time
Today, 04:07
Joined
Oct 8, 2001
Messages
9
Thanks LQ, but this will only work when I print, and I don't want to do that.

Its for an electronic questionnaire so I need to do it as a form.

Regards
Ian
 

jstutz

Registered User.
Local time
Today, 04:07
Joined
Jan 28, 2000
Messages
80
Although I've never tried something like this, you could in theory squash the questions closer together by setting the Top property for your question in code, which in itself is easy. The code would look like:

me!ControlName.top = 1440 'Move this control down 1 inch from the top of the form.

When setting either the top or left properties of an object using code, the unit of measure is "twips" (I'm not pulling your leg, that's what they're called!). One twip is equal to 1/20th of a point or 1/1440 of an inch.

The tricky part is determining what value to assign to each question so you don't stack them on top of one another. There's a number of different ways you could approach this, and which you choose is probably a personal choice. Probably the easiest would be something like this in your OnCurrent event:

----------------------
Private Sub Employed_AfterUpdate()
If Me!Employed = -1 Then 'if check is yes
Me!EmpPayslip.Visible = True
Me!Label17.Visible = True
Me!Label9.Visible = True
Me!Label10.Visible = True
ElseIf Me!Employed = 0 Then 'if check is no
Me!EmpPayslip.Visible = False
Me!Label17.Visible = False
Me!Label9.Visible = False
Me!Label10.Visible = False
End If
End Sub

Private Sub SelfEmployed_AfterUpdate()
If Me!SelfEmployed = -1 Then 'if check is yes
If Me!Employed = -1 Then
Me!SEmpPayslip.Top = X 'Where X is equal to the TOP value of first question
Me!Label18.Top = X
Me!Label13.Top = X
Me!Label14.Top = X
End IF
Me!SEmpPayslip.Visible = True
Me!Label18.Visible = True
Me!Label13.Visible = True
Me!Label14.Visible = True
ElseIf Me!SelfEmployed = 0 Then 'if check is no
If Me!Employed = -1 Then
Me!SEmpPayslip.Top = Y 'Where Y is equal to the initial TOP value of 2nd question
Me!Label18.Top = Y
Me!Label13.Top = Y
Me!Label14.Top = Y
End IF
Me!SEmpPayslip.Visible = False
Me!Label18.Visible = False
Me!Label13.Visible = False
Me!Label14.Visible = False
End If
End Sub
----------------------

Since you only have two questions, you only need to worry about determining if the first one is active. If it is, you set the TOP property of the second question to it's default position value (ie. you keep it in place). If the first question is not used, you then bump the up the 2nd question to the position of the first.

Using this code in the OnCurrent event while cause access to re-evaluate where the second question should be located each time a the form moves to a different record.

Hopefully I was clear in my description on how to accomplish this. Good luck!

js

[This message has been edited by jstutz (edited 10-12-2001).]

[This message has been edited by jstutz (edited 10-12-2001).]
 

Users who are viewing this thread

Top Bottom