Field hidden until yes/no box ticked?

G

Guest

Hello all, is it possible to have a field on a form hidden and only appear if
a tick box is ticked? I have a yes/no tick box for "sample required". I would
like a "sample required date field" to become visible only when the sample
box is ticked. Is this possible?

many thanks for any help.
 
G

Guest

In the form's Current event:

If Me.NewRecord Then
Me.txtSampleRequiredDate.Visible = False
Else
Me.chkSampleRequiredDate.Visible = Me.chkSampleRequired
End If

In the After Update event of the check box:

Me.chkSampleRequiredDate.Visible = Me.chkSampleRequired
 
G

Guest

Hi Dave, i tried your suggestion but had no joy. I am sure it will be a case
of me entering the detail incorrectly. can you confirm that the
"txtSampleRequiredDate" is the name of the field i want to be invisible until
the box is ticked?

Also just to clarify, the tick box will be in the middle of the form, when
ticked the field will appear for entering a date without losing any of the
data already input.
Failing this the tick box could call up a subform called "SampleDetails"
(again not sure how to achieve this).
Is a sub form just the same as a form but it is opened within another form?

many thanks for your help.
 
G

Guest

I would have no way of knowing what your names actually are. I just used the
name you originally posted.
txtSampleRequiredDate is the name of the text box where you want to enter
the date.

chkSampleRequired is the name of the check box you describe.

Now, to see if we have the code implemented correctly. Here is the procedure.

Open the form in design view.
Open the properties dialog for the form
Select the Events Tab
Select the box that says On Current
Click the button to the right with the 3 dots
Select Code Builder
The VBA editor will open with the cursor in the Current Event Sub
Copy and paste the code I posted that says it is for the Current event.

Go back to the form design.
Select the check box
Open the properties dialog for the check box
Select the Events Tab
Select the After Update box
Click the button with the 3 dots
Paste the code I posted for the After Update event in there

Be sure the named I described above match the names of the controls. Change
them if they do not.
 
G

Guest

Hi Dave,
I have another quick query.

where you have "txtsamplerequireddate" i have replaced with my "sampledate".
This being the name of the date text box.

where you have "chksamplerequired" i have replaced with "samplereq" this
being the name of the tick box.

you also have "chksamplerequired" i am unsure what this one is for. Would
this be a label name?

Can i also ask, when the form is opened the sample required tick box will be
visible and unticked. only when it is ticked will the sample date appear on
the form.
This should appear as soon as the box is ticked on the same form that is
already open.

When i go to the next record or open this form again the same will apply
each time.

is this the way the code you have provided will work?

I am beginning to think it might make more sense for me to have a sub form
or a tab that will present a sample details page or section.

Do you have any thoughts on this? I will look through the group for advice
on tabs.

many thanks.

P.S do you have any idea if there are any access websites that list common
routines and procedures that i might find useful.
 

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