Using an expression in a form...Need help bad

G

Goirish1904

I am having a serious problem with this expression that I wrote in a form in
Microsoft Access. What I am trying to do is simple. I have a text box in
the form. I also have a separate check box in the form. The check box is a
yes/no field from the table I am using for my form. What I want to do is
when I click on the check box, I want the date of when I check the check box
to show up in the text box. I have used the expression: =IIf([Check
box]="-1",Date (),"").

This expression works and it gives me the date when the check box is
checked. However, the date always changes as the next day comes. For
example, if I click on the check box on Jan 1st, the text box shows Jan 1st.
If I save the database and come back the next day and open the database, the
date shows Jan 2nd.

I need help on this because this will save me so much time with documenting
data with dates.

Please respond soon. Thank you very much
 
T

tina

i'm assuming that you put the expression

=IIf([Checkbox]="-1",Date (),"")

in the ControlSource property of the textbox. if that's correct, then the
problem is that the textbox control is *not* bound to a field in the
underlying table. so that date that you see is just "for display" - it's not
being saved anywhere.

presumably you do have a field in the underlying table where you want the
date to be stored. if so, then you need to bind the field to that textbox
control, by putting the fieldname in the textbox's ControlSource property.
then add a macro or VBA code to the checkbox's AfterUpdate event to set the
date in that field, as

If Me!CheckboxName = True Then
Me!TextboxControlName = Date
End If

hth
 
J

John W. Vinson

I am having a serious problem with this expression that I wrote in a form in
Microsoft Access. What I am trying to do is simple. I have a text box in
the form. I also have a separate check box in the form. The check box is a
yes/no field from the table I am using for my form. What I want to do is
when I click on the check box, I want the date of when I check the check box
to show up in the text box. I have used the expression: =IIf([Check
box]="-1",Date (),"").

That's not the way to do it.

Select the checkbox in form design view, and view its properties. Click the
.... icon by the AfterUpdate event and choose Code Builder. Access will give
you the sub and end sub lines; add just one more:

Private Sub Check_Box_AfterUpdate()
If Me![Check Box] Then
Me!textboxname = Date
End If
End Sub

John W. Vinson [MVP]
 
G

Goirish1904

Thank you very much for your help. This will make a huge difference at my
job with documenting things and the amount of time this is saving. Thanks a
lot.

tina said:
i'm assuming that you put the expression

=IIf([Checkbox]="-1",Date (),"")

in the ControlSource property of the textbox. if that's correct, then the
problem is that the textbox control is *not* bound to a field in the
underlying table. so that date that you see is just "for display" - it's not
being saved anywhere.

presumably you do have a field in the underlying table where you want the
date to be stored. if so, then you need to bind the field to that textbox
control, by putting the fieldname in the textbox's ControlSource property.
then add a macro or VBA code to the checkbox's AfterUpdate event to set the
date in that field, as

If Me!CheckboxName = True Then
Me!TextboxControlName = Date
End If

hth


Goirish1904 said:
I am having a serious problem with this expression that I wrote in a form in
Microsoft Access. What I am trying to do is simple. I have a text box in
the form. I also have a separate check box in the form. The check box is a
yes/no field from the table I am using for my form. What I want to do is
when I click on the check box, I want the date of when I check the check box
to show up in the text box. I have used the expression: =IIf([Check
box]="-1",Date (),"").

This expression works and it gives me the date when the check box is
checked. However, the date always changes as the next day comes. For
example, if I click on the check box on Jan 1st, the text box shows Jan 1st.
If I save the database and come back the next day and open the database, the
date shows Jan 2nd.

I need help on this because this will save me so much time with documenting
data with dates.

Please respond soon. Thank you very much
 
G

Goirish1904

Thank you very much for you help. The answer was perfect and definitely
worked. I really appreciate this as this will save me a tremendous amount of
time at work and with documentation. Thanks again.

John W. Vinson said:
I am having a serious problem with this expression that I wrote in a form in
Microsoft Access. What I am trying to do is simple. I have a text box in
the form. I also have a separate check box in the form. The check box is a
yes/no field from the table I am using for my form. What I want to do is
when I click on the check box, I want the date of when I check the check box
to show up in the text box. I have used the expression: =IIf([Check
box]="-1",Date (),"").

That's not the way to do it.

Select the checkbox in form design view, and view its properties. Click the
.... icon by the AfterUpdate event and choose Code Builder. Access will give
you the sub and end sub lines; add just one more:

Private Sub Check_Box_AfterUpdate()
If Me![Check Box] Then
Me!textboxname = Date
End If
End Sub

John W. Vinson [MVP]
 
Top