Updating field

  • Thread starter Thread starter Shelly
  • Start date Start date
S

Shelly

I have two fields. The first is a check box (SurveyRec)
and the second is a date field (SurveyDte). What I need
to have happen is when the user clicks on the check box,
check to see if the SurveyDte field is Null and if it is
stick in a date. Here's the code I tried in the OnClick
event of the checkbox...

If [SurveyDte] Is Null Then
[SurveyDte] = "4/1/2004"
Else
[SurveyDte] = Null
End If

Access doesn't like the first line. I tried = Null, and
it doesn't error out, but it also won't update the
field. I've also tried looking at the SurveyRec field,
and update based on it's value, but that won't update
correctly either.

Basically, I need to have the date added when they click
the checkbox to say yes, but if they uncheck it, I'll
need to clear out the SurveyDte field.

Thanks in advance.
Shelly
 
Shelly,

If the field which is bound to your form's SurveyDte control is a Date/Time
type, you will need to change:

"4/1/2004" to #4/1/2004/#

Date literals must always be enclosed in #-signs so that Access will
interpret them as Dates as opposed to Strings, which are enclosed in quotes.


hth,
 
Hi, Shelly,

Try this:

If IsNull(me.SurveyDte) then
Me.SurveyDte = Date() 'this will insert today's date
Else
Me.SurveyDte = Null
EndIf

HTH

Byron
 
Byron...
You are THE MAN!!!

Thanks!
-----Original Message-----
Hi, Shelly,

Try this:

If IsNull(me.SurveyDte) then
Me.SurveyDte = Date() 'this will insert today's date
Else
Me.SurveyDte = Null
EndIf

HTH

Byron
-----Original Message-----
I have two fields. The first is a check box (SurveyRec)
and the second is a date field (SurveyDte). What I need
to have happen is when the user clicks on the check box,
check to see if the SurveyDte field is Null and if it is
stick in a date. Here's the code I tried in the OnClick
event of the checkbox...

If [SurveyDte] Is Null Then
[SurveyDte] = "4/1/2004"
Else
[SurveyDte] = Null
End If

Access doesn't like the first line. I tried = Null, and
it doesn't error out, but it also won't update the
field. I've also tried looking at the SurveyRec field,
and update based on it's value, but that won't update
correctly either.

Basically, I need to have the date added when they click
the checkbox to say yes, but if they uncheck it, I'll
need to clear out the SurveyDte field.

Thanks in advance.
Shelly
.
.
 
Cheryl,

Actually, the quotes work in the code, it was actually a
problem with the conditions to get the field updated
correctly.

Thanks
-----Original Message-----
Shelly,

If the field which is bound to your form's SurveyDte control is a Date/Time
type, you will need to change:

"4/1/2004" to #4/1/2004/#

Date literals must always be enclosed in #-signs so that Access will
interpret them as Dates as opposed to Strings, which are enclosed in quotes.


hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


I have two fields. The first is a check box (SurveyRec)
and the second is a date field (SurveyDte). What I need
to have happen is when the user clicks on the check box,
check to see if the SurveyDte field is Null and if it is
stick in a date. Here's the code I tried in the OnClick
event of the checkbox...

If [SurveyDte] Is Null Then
[SurveyDte] = "4/1/2004"
Else
[SurveyDte] = Null
End If

Access doesn't like the first line. I tried = Null, and
it doesn't error out, but it also won't update the
field. I've also tried looking at the SurveyRec field,
and update based on it's value, but that won't update
correctly either.

Basically, I need to have the date added when they click
the checkbox to say yes, but if they uncheck it, I'll
need to clear out the SurveyDte field.

Thanks in advance.
Shelly


.
 
I have almost exactly the same problem but I can't get
this to work.

I have a check box [informationcorrect] and when it gets
checked I want another field [lastupdated] to populate
today's date.

I put the code below into the on click in the
[informationcorrect?] properties box and change
(me.SurveyDte) to (me.lastupdated) and I got a compile
error. What am I doing wrong?

Maggie
-----Original Message-----
Hi, Shelly,

Try this:

If IsNull(me.SurveyDte) then
Me.SurveyDte = Date() 'this will insert today's date
Else
Me.SurveyDte = Null
EndIf

HTH

Byron
-----Original Message-----
I have two fields. The first is a check box (SurveyRec)
and the second is a date field (SurveyDte). What I need
to have happen is when the user clicks on the check box,
check to see if the SurveyDte field is Null and if it is
stick in a date. Here's the code I tried in the OnClick
event of the checkbox...

If [SurveyDte] Is Null Then
[SurveyDte] = "4/1/2004"
Else
[SurveyDte] = Null
End If

Access doesn't like the first line. I tried = Null, and
it doesn't error out, but it also won't update the
field. I've also tried looking at the SurveyRec field,
and update based on it's value, but that won't update
correctly either.

Basically, I need to have the date added when they click
the checkbox to say yes, but if they uncheck it, I'll
need to clear out the SurveyDte field.

Thanks in advance.
Shelly
.
.
 
Maggie,

Try this:

If Me.informationcorrect = -1 then 'if the checkbox is checked
Me.lastupdated = date()
else
me.lastupdated = vbNullString
End If

HTH,
Debbie


I have almost exactly the same problem but I can't get
this to work.

I have a check box [informationcorrect] and when it gets
checked I want another field [lastupdated] to populate
today's date.

I put the code below into the on click in the
[informationcorrect?] properties box and change
(me.SurveyDte) to (me.lastupdated) and I got a compile
error. What am I doing wrong?

Maggie
-----Original Message-----
Hi, Shelly,

Try this:

If IsNull(me.SurveyDte) then
Me.SurveyDte = Date() 'this will insert today's date
Else
Me.SurveyDte = Null
EndIf

HTH

Byron
-----Original Message-----
I have two fields. The first is a check box (SurveyRec)
and the second is a date field (SurveyDte). What I need
to have happen is when the user clicks on the check box,
check to see if the SurveyDte field is Null and if it is
stick in a date. Here's the code I tried in the OnClick
event of the checkbox...

If [SurveyDte] Is Null Then
[SurveyDte] = "4/1/2004"
Else
[SurveyDte] = Null
End If

Access doesn't like the first line. I tried = Null, and
it doesn't error out, but it also won't update the
field. I've also tried looking at the SurveyRec field,
and update based on it's value, but that won't update
correctly either.

Basically, I need to have the date added when they click
the checkbox to say yes, but if they uncheck it, I'll
need to clear out the SurveyDte field.

Thanks in advance.
Shelly
.
.
 
Debbit - Thank you very much. This worked great! One
thing that is kind of wierd.

I used this code on two different check boxes/update
fields - I just changed the names of the field I wanted to
populate with the date. In one check box as soon as you
check it yes the date is added on the other check box the
date is added after you close the subform. Any idea why
it is different if I set it up the same?

Thanks again,

Maggie
-----Original Message-----
Maggie,

Try this:

If Me.informationcorrect = -1 then 'if the checkbox is checked
Me.lastupdated = date()
else
me.lastupdated = vbNullString
End If

HTH,
Debbie


I have almost exactly the same problem but I can't get
this to work.

I have a check box [informationcorrect] and when it gets
checked I want another field [lastupdated] to populate
today's date.

I put the code below into the on click in the
[informationcorrect?] properties box and change
(me.SurveyDte) to (me.lastupdated) and I got a compile
error. What am I doing wrong?

Maggie
-----Original Message-----
Hi, Shelly,

Try this:

If IsNull(me.SurveyDte) then
Me.SurveyDte = Date() 'this will insert today's date
Else
Me.SurveyDte = Null
EndIf

HTH

Byron
-----Original Message-----
I have two fields. The first is a check box (SurveyRec)
and the second is a date field (SurveyDte). What I need
to have happen is when the user clicks on the check box,
check to see if the SurveyDte field is Null and if it is
stick in a date. Here's the code I tried in the OnClick
event of the checkbox...

If [SurveyDte] Is Null Then
[SurveyDte] = "4/1/2004"
Else
[SurveyDte] = Null
End If

Access doesn't like the first line. I tried = Null, and
it doesn't error out, but it also won't update the
field. I've also tried looking at the SurveyRec field,
and update based on it's value, but that won't update
correctly either.

Basically, I need to have the date added when they click
the checkbox to say yes, but if they uncheck it, I'll
need to clear out the SurveyDte field.

Thanks in advance.
Shelly
.
.

.
 
What event did you put the code into?


Debbit - Thank you very much. This worked great! One
thing that is kind of wierd.

I used this code on two different check boxes/update
fields - I just changed the names of the field I wanted to
populate with the date. In one check box as soon as you
check it yes the date is added on the other check box the
date is added after you close the subform. Any idea why
it is different if I set it up the same?

Thanks again,

Maggie
-----Original Message-----
Maggie,

Try this:

If Me.informationcorrect = -1 then 'if the checkbox is checked
Me.lastupdated = date()
else
me.lastupdated = vbNullString
End If

HTH,
Debbie


I have almost exactly the same problem but I can't get
this to work.

I have a check box [informationcorrect] and when it gets
checked I want another field [lastupdated] to populate
today's date.

I put the code below into the on click in the
[informationcorrect?] properties box and change
(me.SurveyDte) to (me.lastupdated) and I got a compile
error. What am I doing wrong?

Maggie
-----Original Message-----
Hi, Shelly,

Try this:

If IsNull(me.SurveyDte) then
Me.SurveyDte = Date() 'this will insert today's date
Else
Me.SurveyDte = Null
EndIf

HTH

Byron
-----Original Message-----
I have two fields. The first is a check box (SurveyRec)
and the second is a date field (SurveyDte). What I need
to have happen is when the user clicks on the check box,
check to see if the SurveyDte field is Null and if it is
stick in a date. Here's the code I tried in the OnClick
event of the checkbox...

If [SurveyDte] Is Null Then
[SurveyDte] = "4/1/2004"
Else
[SurveyDte] = Null
End If

Access doesn't like the first line. I tried = Null, and
it doesn't error out, but it also won't update the
field. I've also tried looking at the SurveyRec field,
and update based on it's value, but that won't update
correctly either.

Basically, I need to have the date added when they click
the checkbox to say yes, but if they uncheck it, I'll
need to clear out the SurveyDte field.

Thanks in advance.
Shelly
.
.

.
 
OnClick

One thing though - the second check box that when clicked
populates right away is the last tab stop in the record.

Sorry for spelling your name wrong.

Thanks,

Maggie
-----Original Message-----
What event did you put the code into?


Debbit - Thank you very much. This worked great! One
thing that is kind of wierd.

I used this code on two different check boxes/update
fields - I just changed the names of the field I wanted to
populate with the date. In one check box as soon as you
check it yes the date is added on the other check box the
date is added after you close the subform. Any idea why
it is different if I set it up the same?

Thanks again,

Maggie
-----Original Message-----
Maggie,

Try this:

If Me.informationcorrect = -1 then 'if the checkbox is checked
Me.lastupdated = date()
else
me.lastupdated = vbNullString
End If

HTH,
Debbie


I have almost exactly the same problem but I can't get
this to work.

I have a check box [informationcorrect] and when it gets
checked I want another field [lastupdated] to populate
today's date.

I put the code below into the on click in the
[informationcorrect?] properties box and change
(me.SurveyDte) to (me.lastupdated) and I got a compile
error. What am I doing wrong?

Maggie
-----Original Message-----
Hi, Shelly,

Try this:

If IsNull(me.SurveyDte) then
Me.SurveyDte = Date() 'this will insert today's date
Else
Me.SurveyDte = Null
EndIf

HTH

Byron
-----Original Message-----
I have two fields. The first is a check box (SurveyRec)
and the second is a date field (SurveyDte). What I need
to have happen is when the user clicks on the check box,
check to see if the SurveyDte field is Null and if it is
stick in a date. Here's the code I tried in the OnClick
event of the checkbox...

If [SurveyDte] Is Null Then
[SurveyDte] = "4/1/2004"
Else
[SurveyDte] = Null
End If

Access doesn't like the first line. I tried = Null, and
it doesn't error out, but it also won't update the
field. I've also tried looking at the SurveyRec field,
and update based on it's value, but that won't update
correctly either.

Basically, I need to have the date added when they click
the checkbox to say yes, but if they uncheck it, I'll
need to clear out the SurveyDte field.

Thanks in advance.
Shelly
.

.

.

.
 
Back
Top