Visibility Code

  • Thread starter ladybug via AccessMonster.com
  • Start date
L

ladybug via AccessMonster.com

I have a field on a form that is "Date." I have the Date field set to =Now().
There is another field that is a check box called "Adverse Event."
Currently when I open the form the Date field shows the current time and date.
I want the Date and Time to only be visible when the check box is selected.
Is there an On Update code that I can use for this? Please be specific, I am
not fluent in code. Thank you in advance for any assistance!
 
K

Klatuu

If you are using Date as a control or field name, you should change it. Date
is a reserved word and using it as a name may cause problems.

To do what you want, make the Visible property of the date text box control No

Then use the After Update event of the check box control to make the date
text box Visible or Not:

Private Sub MyCheckBox_AfterUpdate()
Me.DateTextBox.Visible = Me.MyCheckBox
End Sub

You will have to use your own names for this code, of course.

Now to explain. A check box control will return either True or False. The
Visibility property of a control is set using True or False. So when you
click to make the check box true, it will cause the date text box to be
visible.
 
L

ladybug via AccessMonster.com

I changed the date name to AdverseEventDate.

I used your code and changed the names. This is what I came up with:
Private Sub AdverseEvent_AfterUpdate()
Me.AdverseEventDate.Visible = Me.AdverseEvent
End Sub

The date and time do not appear when I select the check box. I also rcv this
error:
Ambiguous name detected: AdverseEvent_AfterUpdate

I checked, the checkbox name is AdverseEvent. Do you why this is not working?
 
K

Klatuu

Does that happen when you check the check box?
Open your form in design view, select the check box, and open the properties
dialog. Select the events tab then see what is in the AfterUpdate event. If
it does not say [Event Procedure] then it doesn't know the event exists.
If is is saying there is an ambiguous name, then you have two subs with the
same name.
 
L

ladybug via AccessMonster.com

Ok, I have it working now. One more question. The date and time does not
stay once I close the form and open it back up. How do I get it to stay?

Does that happen when you check the check box?
Open your form in design view, select the check box, and open the properties
dialog. Select the events tab then see what is in the AfterUpdate event. If
it does not say [Event Procedure] then it doesn't know the event exists.
If is is saying there is an ambiguous name, then you have two subs with the
same name.
I changed the date name to AdverseEventDate.
[quoted text clipped - 33 lines]
 
K

Klatuu

Not sure what you mean. Do you mean the date and time in AdverseEventDate?
Is that not captured in the table?
--
Dave Hargis, Microsoft Access MVP


ladybug via AccessMonster.com said:
Ok, I have it working now. One more question. The date and time does not
stay once I close the form and open it back up. How do I get it to stay?

Does that happen when you check the check box?
Open your form in design view, select the check box, and open the properties
dialog. Select the events tab then see what is in the AfterUpdate event. If
it does not say [Event Procedure] then it doesn't know the event exists.
If is is saying there is an ambiguous name, then you have two subs with the
same name.
I changed the date name to AdverseEventDate.
[quoted text clipped - 33 lines]
Is there an On Update code that I can use for this? Please be specific, I am
not fluent in code. Thank you in advance for any assistance!
 
L

ladybug via AccessMonster.com

Yes the date and time in AdverseEventDate and yes it is captured in the table.

The field for date/time and the check box are on a subform. this subform is
linked to an autonumber on the main form.
The code works for when I select the checkbox, but when I close the form and
then go back in and open that entry the checkbox is still checked, but the
Date and Time are not visible.
Not sure what you mean. Do you mean the date and time in AdverseEventDate?
Is that not captured in the table?
Ok, I have it working now. One more question. The date and time does not
stay once I close the form and open it back up. How do I get it to stay?
[quoted text clipped - 10 lines]
 
K

Klatuu

Because you are in a datasheet or continuous form, this can be an issue. I
don't really have a suggestion to help.
--
Dave Hargis, Microsoft Access MVP


ladybug via AccessMonster.com said:
Yes the date and time in AdverseEventDate and yes it is captured in the table.

The field for date/time and the check box are on a subform. this subform is
linked to an autonumber on the main form.
The code works for when I select the checkbox, but when I close the form and
then go back in and open that entry the checkbox is still checked, but the
Date and Time are not visible.
Not sure what you mean. Do you mean the date and time in AdverseEventDate?
Is that not captured in the table?
Ok, I have it working now. One more question. The date and time does not
stay once I close the form and open it back up. How do I get it to stay?
[quoted text clipped - 10 lines]
Is there an On Update code that I can use for this? Please be specific, I am
not fluent in code. Thank you in advance for any assistance!
 
L

ladybug via AccessMonster.com

The subform is set to Single Form. Is there an OnOpen code I can use on the
form itself?
Klatuu said:
Because you are in a datasheet or continuous form, this can be an issue. I
don't really have a suggestion to help.
Yes the date and time in AdverseEventDate and yes it is captured in the table.
[quoted text clipped - 11 lines]
 
K

Klatuu

The Load event of the form would be preferrable to the Open; however, you may
try using the form's Current event

If Me.NewRecord Then
AdverseEventDate.Visible = False
AdverseEvent = False
Else
AdverseEventDate.Visible = AdverseEvent
End IF

--
Dave Hargis, Microsoft Access MVP


ladybug via AccessMonster.com said:
The subform is set to Single Form. Is there an OnOpen code I can use on the
form itself?
Klatuu said:
Because you are in a datasheet or continuous form, this can be an issue. I
don't really have a suggestion to help.
Yes the date and time in AdverseEventDate and yes it is captured in the table.
[quoted text clipped - 11 lines]
Is there an On Update code that I can use for this? Please be specific, I am
not fluent in code. Thank you in advance for any assistance!
 
L

ladybug via AccessMonster.com

Ok, so that kind of worked. Something I did notice is that when you open the
form say it is 2:05pm. If you leave that form open and then later go and
select the check box at 2:16pm, the date/time stamp says 2:05pm. I need it
to stamp at the time they select the check box (2:16pm).
Sorry to be so difficult. You really have taught me a lot and I greatly
appreciate it.
The Load event of the form would be preferrable to the Open; however, you may
try using the form's Current event

If Me.NewRecord Then
AdverseEventDate.Visible = False
AdverseEvent = False
Else
AdverseEventDate.Visible = AdverseEvent
End IF
The subform is set to Single Form. Is there an OnOpen code I can use on the
form itself?
[quoted text clipped - 5 lines]
 
K

Klatuu

The code in the after update event of the AdverseEvent check box should do
that:
If Me.AdverseEvent = True Then
Me.AdverseEventDate.Visisble = True
Me.AdverseEventDate = Date
Else
Me.AdverseEventDate.Visisble = False
End If
--
Dave Hargis, Microsoft Access MVP


ladybug via AccessMonster.com said:
Ok, so that kind of worked. Something I did notice is that when you open the
form say it is 2:05pm. If you leave that form open and then later go and
select the check box at 2:16pm, the date/time stamp says 2:05pm. I need it
to stamp at the time they select the check box (2:16pm).
Sorry to be so difficult. You really have taught me a lot and I greatly
appreciate it.
The Load event of the form would be preferrable to the Open; however, you may
try using the form's Current event

If Me.NewRecord Then
AdverseEventDate.Visible = False
AdverseEvent = False
Else
AdverseEventDate.Visible = AdverseEvent
End IF
The subform is set to Single Form. Is there an OnOpen code I can use on the
form itself?
[quoted text clipped - 5 lines]
Is there an On Update code that I can use for this? Please be specific, I am
not fluent in code. Thank you in advance for any assistance!
 
L

ladybug via AccessMonster.com

You are a genius!!! Thank you sooo much!
The code in the after update event of the AdverseEvent check box should do
that:
If Me.AdverseEvent = True Then
Me.AdverseEventDate.Visisble = True
Me.AdverseEventDate = Date
Else
Me.AdverseEventDate.Visisble = False
End If
Ok, so that kind of worked. Something I did notice is that when you open the
form say it is 2:05pm. If you leave that form open and then later go and
[quoted text clipped - 18 lines]
 
K

Klatuu

Glad I could help.
--
Dave Hargis, Microsoft Access MVP


ladybug via AccessMonster.com said:
You are a genius!!! Thank you sooo much!
The code in the after update event of the AdverseEvent check box should do
that:
If Me.AdverseEvent = True Then
Me.AdverseEventDate.Visisble = True
Me.AdverseEventDate = Date
Else
Me.AdverseEventDate.Visisble = False
End If
Ok, so that kind of worked. Something I did notice is that when you open the
form say it is 2:05pm. If you leave that form open and then later go and
[quoted text clipped - 18 lines]
Is there an On Update code that I can use for this? Please be specific, I am
not fluent in code. Thank you in advance for any assistance!
 

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