I'd previously thought about that there might be another date function out
there. I figured it had to be local to the form (else it'd fail elsewhere),
but I've previous searched (Ctrl-F) for other instances in the module, &
project, for "date" and gotten only hits on substrings containing "date"
(usually 'AfterUpdate' in the procedure names), except for the one other call
to date that works normally.
When I do the F2 search for "date" I do see two entries with just "Date"
under the member column. One is the VBA (library) with a DateTime (class);
the other has a library class that specifies my DB as the library with the
form name as the Class. So it does look like it at least Thinks there's
another one out there, but I can't find it.
I've tried it with Parens and the editor clears them when I leave the line.
Compiling does not seem to be an option (it's greyed out). I confess to
being a bit of a novice on the VB tools side. I've done a lot of VB behind
buttons and controls, but haven't really used much of the debug and compile
features.
I've added to the weirdness though. Figured if there's a duplicate I can't
find, I'll do a careful copy/paste into a new form (till it breaks, or
hopefully just keeps working). New button with just "msgbox date" on a new
form, gets me the same broken results. Copied one of the functioning forms,
deleted all the controls, same sort of button, works. I started copying just
a few items at a time (no code) and it kept working right until I realized I
didn't set the data source yet. When I enter that, it broke like before.
The source query has a field called just "date", which I deleted since it
wasn't really needed. Now the button on the new form (both new forms) work
properly, but on the old form gives an error (Runtime 2465) that it can't
find the field named 'Date'. But there are no brackets (or anything else)
around the 'date' in the VB.
Jerry Whittle said:
Very, very strange indeed. Importing the form should have found any
corruption issues. Rebuilding the form should have removed the problem. I
have to wonder about the code behind those forms.
Speaking of code, there are a few possibilities. One would be that someone
created another Date function. Bring up the VB window and press the F2 key.
Type in Date and search all Libraries. Make sure that there is only one Date
member.
While in the VB window, go to Debug, Compile and see if there are any errors.
In your code make it look like: [stdate]=Date() . The () might not stick
but it's worth a try.
You might also try a decompile/recompile. Google Access decompile and you
should find some instructions.
Yes, [stdate] is a date/time field in a table where I'm keeping track of
when the records have been updated. It's an invisible field that is set
automatically at some point after the user has pressed a button to indicate
they're done with the entry (some checking and action logic happens before
the field is set). I'd rather keep the field invisible than rely on users to
update it, but there's nothing that keeps me from changing it after the
erroneous value is input.
Just to simplify the error testing, I've created a button on each form with
the only the following visual basic: "msgbox date". 2 out of the 3 forms in
the database print right, with the (same) third one printing the strange
date&time value.
I've imported the form to a new database (actually all the DB objects) and
also recreated the form by copy/paste of the objects and then code to a new
form (prior to the original post even). The results are the same.
The Now() function works and could be used as a work-around, but I'm
concerned about reliability (what else might not run right).
:
Interesting. Is [stdate] bound to a table? Possibly it is showing the date in
in existing record. Other than that maybe the default value for that field is
set up differently in the table or form.
Could it actually be a label that someone typed a date into?
Can you click into the field and manually type in the correct date?
BTW: The Date function should only give you the date and no time. Now()
gives you both. That's why I think the Date function isn't actually coming to
play here.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.
:
I've got a small DB and I'm tracking usernames & dates for when data is
entered into the main table. I use a different form depending on the type of
entry being made, though the Visual Basic is the same for filling in the
tracking info.
On one form [stdate]=Date functions as expected giving me 3/8/07 (today's
date). On the other form, [stdate]=Date gives me 2/28/07 4:55:21 PM (time
does not appear to change-I don't know if the day changes).
Does anyone have an idea of why or what should be (un)set to make the date
function work right on both forms?