Help going crazy! Uncheck of check box also updates date field ARRGHH!

  • Thread starter Thread starter datahead22
  • Start date Start date
D

datahead22

HELP! PLEASE!!!
Hey gang you guys have been really an incredible resource to me so far
but I've been searching here for a while and I don't see anything quite
like my problem.

I have a check box that OnClick sets the value of a text box to Date()
This is being handled by a macro.
If you have the code I can use that too.

The problem is if you uncheck the box since it's an OnClick event it
sets the date again to date().

What I need is if you check the box it sets the date if you uncheck it
leaves the Date set at what it was when you first checked the box.


Thank You all Very much for the code and answers I have already used!

And thank you for taking the time to help with this mess!

THANKS!!!!
 
HELP! PLEASE!!!
Hey gang you guys have been really an incredible resource to me so far
but I've been searching here for a while and I don't see anything quite
like my problem.

I have a check box that OnClick sets the value of a text box to Date()
This is being handled by a macro.
If you have the code I can use that too.

The problem is if you uncheck the box since it's an OnClick event it
sets the date again to date().

What I need is if you check the box it sets the date if you uncheck it
leaves the Date set at what it was when you first checked the box.

Remove the macro from the Click event, and instead select the ... icon
by the control's AfterUpdate event; choose Code Builder.

Put in code like:

Private Sub chkMyCheckbox_AfterUpdate()
If Me!chkMyCheckbox Then ' if it is now True, set the date
Me!txtDateChecked = Date
End If
End Sub

John W. Vinson[MVP]
 
John, I think he wants it to act on the unlick as well. Unclick should
set it back to "what it was [before] you first clicked the box".

OP, try the following change. It might or might not work, depending on
your situation.

Private Sub chkMyCheckbox_AfterUpdate()
If Me!chkMyCheckbox Then ' if it is now True, set the date
Me!txtDateChecked = Date
Else
Me!txtDateChecked.Undo
End If
End Sub

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
Thanks John W. Vinson[MVP] & TC you guys are life savers I don't no
which one is exactly right but the code for both looks right on the
money thanks!!! I didn't know I would get a response so soon!!!

I think I have two more tough questions for you if you think you would
have time for them????
 
Thanks John W. Vinson[MVP] & TC you guys are life savers I don't no
which one is exactly right but the code for both looks right on the
money thanks!!! I didn't know I would get a response so soon!!!

I think I have two more tough questions for you if you think you would
have time for them????

We're all volunteers here, and a lot of us are somewhat addicted to
helping people. The store's always open and generally someone will
answer within a very few hours.


John W. Vinson[MVP]
 
Maybe I'm missing something or maybe it's just to early in the morning
below is the code I put together

Private Sub Turn_away_AfterUpdate()
If Me!Turn_Away = True Then
Forms!frm_Resident!turn_away_date = date
End If
End Sub

Now if there is a date in the field turn_away_date when you uncheck
the check box it leaves the date that is there like it's supposed to
which great but when it is checked it is not updating the field with
the date instead it blows out the record????
 
Uh, what does: "blows out the record" mean?

Please try not to use such terms. It just wastes everyones' time, while
we ask you what you mean. I find that very frustrating!

I note this line in your code:
Forms!frm_Resident!turn_away_date = date

If the form containing that code, is called frm_Resident, you should
change that line of code to this:
Me![turn_away_date] = date

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
Sorry about the "blows out the record" TC it appears that instead of
setting the text box [turn_away_date] to todays date,
it seems to delete the record in the table.
The uncheck function appears to be working perfectly!
I have changed the line of code as you suggested and I'm still getting
the same result.
This is how the code reads now

Private Sub Turn_away_AfterUpdate()
If Me!Turn_Away = True Then
Me![turn_away_date] = date
End If
End Sub

Do you think it might be because the field in the table is formatted to
be a short date and has an input mask of 99/99/0000;0;_,
Sorry I don't mean to frustrate you or waste your time.
 
Now if there is a date in the field turn_away_date when you uncheck
the check box it leaves the date that is there like it's supposed to
which great but when it is checked it is not updating the field with
the date instead it blows out the record????

Is it actually deleting the record FROM THE TABLE? There's nothing in
the code you posted which would do so. Might the Form have some filter
which is hiding records where the checkbox is true, or the date field
is not Null?

John W. Vinson[MVP]
 
I have not put any filters on the form to hide records in the date
field "turn_away_date"

I'm sorry I don't think I've been very clear let me try again.
When the user checks the box "Turn_away" I need the Text box
"turn_away_date" to have its value set to date()
if the user unchecks the box the date previously captured should stay
in that box.

So if I checked the box yesterday the value in the table and text box
would say 03/22/2006
If I uncheck the box today the value in the table and text box should
still say 03/22/2006
but if I check the box again today it should update with today's date
03/23/2006

What is happening currently is if the field displays 03/22/2006 and the
box "Turn_away" is checked and I uncheck the box Turn_away the text box
retains the value 03/22/2006 and that is perfect.
However when I check the box "Turn_away" again the text field and the
record in the table become empty instead of updating with today's
date.

I hope this clarifies my needs. But I have a feeling today that I'm
coming across as clear as mud.
 
I'm sorry I don't think I've been very clear let me try again.
When the user checks the box "Turn_away" I need the Text box
"turn_away_date" to have its value set to date()
if the user unchecks the box the date previously captured should stay
in that box.

So if I checked the box yesterday the value in the table and text box
would say 03/22/2006
If I uncheck the box today the value in the table and text box should
still say 03/22/2006
but if I check the box again today it should update with today's date
03/23/2006

The code you posted should do just exactly that:

Private Sub Turn_away_AfterUpdate()
If Me!Turn_Away = True Then
Forms!frm_Resident!turn_away_date = date
End If
End Sub
What is happening currently is if the field displays 03/22/2006 and the
box "Turn_away" is checked and I uncheck the box Turn_away the text box
retains the value 03/22/2006 and that is perfect.
However when I check the box "Turn_away" again the text field and the
record in the table become empty instead of updating with today's
date.

Are you certain it's not just navigating to the empty New Record? Try
setting the Form's Cycle property to stay on the same record...

John W. Vinson[MVP]
 
Ok, your description is very clear now :-)

I agree with John: there's no way the code that you have shown us,
would normally delete the record. It must be something else. But I'm
rather stumped to think what it is!

As well as John's suggestions,. if you think it might be something to
do with the format on the date field in the table, try temporarily
removing that fomat, and see if it still happens.

Remember when you're testing all this, to use the exact same sequence
of keystrokes, every time. The problem might rely on exactly what you
do & how/when you do it.

If nothing else works, depending on the number of lines of code in your
form's code module, you could maybe post the whole lot here: inside a
post, not as an attachment.

I recommend that you keep trying with this. There's no way it is normal
Access behaviour. My bet is, the problem will be very simple - as soon
as we can actually find it!

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
Well I haven't figured out exactly what it is but I think it has
something to do with the table. The code is correct I can put it
together on new tables and new forms and it works just like it should.
Here's hoping I figure it out soon I've got a bunch of these check
boxes through out the app that I've got to get working.
 
As suggested it was something simple it did not have to do with the
table but I think access was getting caught in some sort of circular
reference because I was trying to use date to update a field with date
in the name. I simply changed the code to read:
Private Sub Turn_away_AfterUpdate()
If Me!Turn_Away = True Then
Me![turn_away_date] = Now
End If
End Sub
And it WORKS!!!
Thanks Again for all Your help!!!
 
Back
Top