checkbox coding problem

  • Thread starter Thread starter supersonix
  • Start date Start date
S

supersonix

I'm having an issue coding a check box in relation to a date field
combo box that I'm hoping someone can assist me with. Here are the
particulars:

I have a combo box (cboDate) using the calendar control for the user
to select the date. I wanted the combo box to show yesterdays date by
default so I set the default value to Date()-1.

This works just fine but I wanted to add the option of a user adding
multiple records with a different date (other than yesterday or
date()-1) without the need to always select the date. In other words
if a user had 10 records to add for last thurs they could select that
date from the calendar and click on a checkbox to keep that date
selected while they added the 10 records. Once completed they could
uncheck the checkbox and it would revert back to date()-1.

I tried coding it like

if me.checkbox = true then
cboDate.defaultvalue = cboDate.value
else
cboDate.defaultvalue = Date() - 1
end if

This obviously doesn't seem to work properly. Any assistance would be
appreciated.

Thanks!
Lalit
 
Try
if me.checkbox = true then
cboDate.defaultvalue = "=#" & Format(cboDate.value,"yyyy-mm-dd") & "#"
else
cboDate.defaultvalue = "=Date() - 1"
end if

You may not need the *extra* = sign

HTH

Pieter
 
Thanks Pieter, it works great! I can definitely work with this but I
just wanted to ask for my own knowledge....once the checkbox is
unchecked the combobox date doesn't switch back to 'date-1' until the
current record is saved. Would there be a way to have it change back
as soon as the checkbox is unchecked?

Thanks again!
 
try
cboDate.Value = Date()-1
' or maybe a requery will suffice?
' cboDate.Requery
Play around ;-)

Pieter
 
Back
Top