Setting Default Value on a Date Field

R

rm

Greetings. I have a data entry form that (among other data) has a date
field. The form is used to allow a person to enter N records for a
given date. The given date may be any date <= to today. For the case
where the date is != Date() then we have placed a checkbox on the form
so that when checked the given date entered by the user in the first
record is held for the entire set of records for that given date. I
tried the following in Form_Current

If form.newrecord then
If checkboxkeepdate.value = -1 then
txtdate.defaultvalue = m_dateKeep
End if
End if

(the code in the form compiles clean. The code is only a
representation of the actual code. I do not have access to the live
code from this computer.) m_dateKeep is populated in the after update
event of the control. I am not having any issues with populating
m_dateKeep. It is the last value entered in the control by the user.
When I set a breakpoint on "txtdate.defaultvalue = m_dateKeep" I can
see the m_dateKeep is properly populated. The problem is that the
value displayed in the date field is 12/30/1899. So I tried setting
the value of the date field instead "txtdate.value = m_dateKeep". The
date appears as expected. However if the user tabs through the fields
in the form 1 too many times then a new record then a new record is
created with nothing but the date field populated. That is not
acceptable. I have used "txtboxfillintheblank.defaultvalue = value" in
other places with success. Any advice?
 
A

Allen Browne

DefaultValue is a Text property, so you need to assign a string:
Me.txtdate.DefaultValue = """" & mdateKeep & """"

The date you were seeing is Access' zero-date, as you can see if you type
this expression into the Immediate Window (Ctrl+G):
? Format(0, "Short Date")
 
R

rm

Thank you! I will give that a shot. Regards.

DefaultValue is a Text property, so you need to assign a string:
    Me.txtdate.DefaultValue = """" & mdateKeep & """"

The date you were seeing is Access' zero-date, as you can see if you type
this expression into the Immediate Window (Ctrl+G):
    ? Format(0, "Short Date")

--
Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.








- Show quoted text -
 

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