access 2007 - display only IF tick box

bede123
bede123 used Ask the Experts™
on
hiya,

i have a very simple form. one of the fields on the form i'd like it only to appear IF i put a tick in a yes/no tick box.

is this possible please? if so how?

zac
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
Yes.

1.  Usethe Click event of the textbox.  Something like:

Private Sub chkFieldName_Click

     me.OtherControlName.Visible = me.chkControlName

End Sub

2.  You will also need to put this code in the Current event of the form, so that when you navigate between records it will automatically hide/unhide that control based on the status of that checkbox.

Private Sub Form_Current

    me.OtherControlName.Visible = me.chkControlName

End Sub

Author

Commented:
ok so if my tick box is called  AR  and my text box is called DATE would the text box on click event look like this:

Private Sub AR_Click()
Me.DATE.Visible = Me.AR
End Sub

??
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:

Yes,

But you should really implement a naming convention for your controls, and [Date] is a reserved word in Access and really should not be used as a field name.

How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Author

Commented:
yes i just used DATE for the example.

here is a cut and paste of all the code:

Option Compare Database

Private Sub AlarmResponse_Click()
Me.CallReceived.Visible = Me.AlarmResponse

End Sub

Private Sub Form_Current()
    Me.CallReceived.Visible = Me.AlarmResponse

End Sub


my tick box yes/no is actually called AlarmResponse
and my text field that i want to hide is called CallReceived


it seems to be throwing an error
error
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
is your checkbox set to TripleState = Yes?  This would allow 0, NULL, and -1 values.  I would turn this off.  Then you need to set the default value of the checkbox to either True or False.  Give that a try and post back.

You could remark out the Current event code temporarily to make sure the Click event is working.  Then, once you know the Click event is working correctly, you could unremark the Current event and work on it.

Author

Commented:
ok so TripleState is NO

default value is now    No

it doesnt appear to throw an error now but it isnt actually doing anything when i tick or untick the AlarmResponse tick box

are you sure ive got the code bit right?
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:

How did you enter that code?  Did you open the form in design view, click on the checkbox, then go to the properties dialog, events tab, and select the Click Event, selecte [Event Procedure] from the dropdown, and then click the "..." to go to the code window, or did you just copy the code into a code module.

If you didn't do it as indicated above, then the object and the code may not actually be associated with each other.

Author

Commented:
i just did a quick screen cast. is this ok what i'm doing?


bede123-486092.flv

Author

Commented:
any ideas?
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Check your code, you misspelled "AlarmResponse"

Author

Commented:
my code has chnaged several times since then.

currently it is:

Private Sub AlarmResponse_Click()
Me.CallReceived.Visible = Me.AlarmResponse

End Sub

Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Have you enabled macro code?

without looking at your database, I cannot tell what you are doing wrong, so I've enclosed a simple example.
CheckboxAction.mdb

Author

Commented:
no the only macro code that exists so far is for a 'save record' button

thanks for the demo. i'll download and have a go.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
When I asked have you enabled macro code, what I meant was:

when you open an Access application which contains macros or VBA code, you will normally see a Security warning. Security Warning
If you click the "Options" button you will get a Security Options dialog box.Security Options dialog
Click the "Enable this Content" button.  If you don't do this, no code behind your forms will work.

Having said, that, you can also put your files in a Trusted Location but you have to be careful about code you have gotten from others.

Author

Commented:
oh yes for sure ive done that. thought you ment something else.

your example does certainly work - but now i'm scraching my head as to why mine wont. i'm going to try making this form from scratch.

Author

Commented:
i just got it to work using this:

Option Compare Database
Option Explicit



Private Sub chk_AlarmResponse_AfterUpdate()
If Me![chk_AlarmResponse] = -1 Then
Me![txt_CallReceived].Visible = True
Me![lbl_CallReceived].Visible = True
Else
Me![txt_CallReceived].Visible = False
Me![lbl_CallReceived].Visible = False
End If
End Sub



Private Sub Form_Current()
If Me![chk_AlarmResponse] = -1 Then
Me![txt_CallReceived].Visible = True
Me![lbl_CallReceived].Visible = True
Else
Me![txt_CallReceived].Visible = False
Me![lbl_CallReceived].Visible = False
End If
End Sub

Open in new window


are there any down sides to doing it this way?
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
No, not really.  My way is just easier to type

Try this:

Private Sub chk_AlarmResponse_AfterUpdate()

    Me![txt_CallReceived].Visible = (Me![chk_AlarmResponse] = -1)
    Me![lbl_CallReceived].Visible = (Me![chk_AlarmResponse] = -1)

End Sub

Author

Commented:
yep that works too!

thanks a lot for your help.

look out for my other questions!  :-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial