Hiding and Unhiding fields on a form

A

Alan

There may be a simple answer to this but I've afraid it's beyond me! I am
trying to make a combo box appear only when a Check Box is 'ticked'. Can
anyone help? i am using Access 2007 and have only one table in my database.

Thanks in advance.

Alan.
 
P

Piet Linden

There may be a simple answer to this but I've afraid it's beyond me!  Iam
trying to make a combo box appear only when a Check Box is 'ticked'.  Can
anyone help?  i am using Access 2007 and have only one table in my database.

Thanks in advance.

Alan.

use the AfterUpdate event of the checkbox.

Sub MyCheckbox_AfterUpdate()
me.cbxAny.Visible=myCheckbox.Checked
End Sub
 
M

Marshall Barton

Alan said:
There may be a simple answer to this but I've afraid it's beyond me! I am
trying to make a combo box appear only when a Check Box is 'ticked'. Can
anyone help? i am using Access 2007 and have only one table in my database.


Use the check box's AfterUpdate event procedure to do that:
Me.thecombobox.Visible = Me.thecheckbox

If the check box is bound to a field in the form's record
source, put the same line of code in the form's Current
event procedure.
 
A

Alan

Thanks Piet. I tried the undernoted in the AfterUpdate and in Form OnCurrent
and it seems to be working.

Kind regards,

alan.

If [TM] = "-1" Then
[TMMInv].Visible = True
[TM].Visible = True
Else
[TMMInv].Visible = False
[TM].Visible = True
End If
If [TM] = "-1" Then
[TMMAct].Visible = True
[TM].Visible = True
Else
[TMMAct].Visible = False
[TM].Visible = True
End If
 
A

Alan

Thanks Marshall. I used the undernoted on the AfterUpdate and on the Form
OnCurrent and it seems to be working.

If [TM] = "-1" Then
[TMMInv].Visible = True
[TM].Visible = True
Else
[TMMInv].Visible = False
[TM].Visible = True
End If
If [TM] = "-1" Then
[TMMAct].Visible = True
[TM].Visible = True
Else
[TMMAct].Visible = False
[TM].Visible = True
End If
Kind regards,

Alan
 
M

Marshall Barton

That a lot of code compared to what Piet and I recommended:
Me.TMMInv.Visible = Me.TM
Me.TMMAct.Visible = Me.TM
Me.TM.Visible = Not Me.TM

Or, if you really feel the need to use an If block:
If Me.TM Then
Me.TMMInv.Visible = True
Me.TMMAct.Visible = True
Me.TM.Visible = False
Else
Me.TMMInv.Visible = False
Me.TMMAct.Visible = False
Me.TM.Visible = True
End If

But you're the one that has to read and work with the code
so it's your call.

One important point, the value of a chack box is not a
string so you should not put quotes around the -1
--
Marsh
MVP [MS Access]

Thanks Marshall. I used the undernoted on the AfterUpdate and on the Form
OnCurrent and it seems to be working.

If [TM] = "-1" Then
[TMMInv].Visible = True
[TM].Visible = True
Else
[TMMInv].Visible = False
[TM].Visible = True
End If
If [TM] = "-1" Then
[TMMAct].Visible = True
[TM].Visible = True
Else
[TMMAct].Visible = False
[TM].Visible = True
End If

Marshall Barton said:
Use the check box's AfterUpdate event procedure to do that:
Me.thecombobox.Visible = Me.thecheckbox

If the check box is bound to a field in the form's record
source, put the same line of code in the form's Current
event procedure.
 
A

Alan

Thanks Marshall, this is very much appreciated.

Marshall Barton said:
That a lot of code compared to what Piet and I recommended:
Me.TMMInv.Visible = Me.TM
Me.TMMAct.Visible = Me.TM
Me.TM.Visible = Not Me.TM

Or, if you really feel the need to use an If block:
If Me.TM Then
Me.TMMInv.Visible = True
Me.TMMAct.Visible = True
Me.TM.Visible = False
Else
Me.TMMInv.Visible = False
Me.TMMAct.Visible = False
Me.TM.Visible = True
End If

But you're the one that has to read and work with the code
so it's your call.

One important point, the value of a chack box is not a
string so you should not put quotes around the -1
--
Marsh
MVP [MS Access]

Thanks Marshall. I used the undernoted on the AfterUpdate and on the Form
OnCurrent and it seems to be working.

If [TM] = "-1" Then
[TMMInv].Visible = True
[TM].Visible = True
Else
[TMMInv].Visible = False
[TM].Visible = True
End If
If [TM] = "-1" Then
[TMMAct].Visible = True
[TM].Visible = True
Else
[TMMAct].Visible = False
[TM].Visible = True
End If

Marshall Barton said:
Alan wrote:
There may be a simple answer to this but I've afraid it's beyond me! I am
trying to make a combo box appear only when a Check Box is 'ticked'. Can
anyone help? i am using Access 2007 and have only one table in my database.


Use the check box's AfterUpdate event procedure to do that:
Me.thecombobox.Visible = Me.thecheckbox

If the check box is bound to a field in the form's record
source, put the same line of code in the form's Current
event procedure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top