Reputation: 5779
In VBA, I am setting a field in a form equal to a string like so:
tmpNum=1
me.field="DD" & Format(DATE, "mmddyy") & tmpNum
For today I would want me.field to be DD0428151 but instead the whole Format(DATE, "mmddyy") statement seemingly does nothing and I get DD1 in the form.
Does anyone understand why the date isn't appearing in my string and how to fix it?
Upvotes: 2
Views: 427
Reputation: 123849
Strange things like this can happen if you have a field named Date
in your table and/or a control named Date
on your form. They will (at least sometimes) take precedence over the built-in Date
function, and if they contain Null
then the results can be similar to what you describe.
If possible, change the name of the field from Date
to something more descriptive (or at least different). If you cannot change the name of the field then consider changing the Record Source of the form to something like
SELECT Table1.Foo, Table1.Date AS TheDate, ... FROM Table1
and then have your form use TheDate
when it needs to manipulate the field or control.
Upvotes: 3