Can't Find the Date field

P

poorboy13

Hello,
I am having an issue where I need to have a field on a form populated by the
'Date' Function by a click on a command button.
However I am getting an error message that Access can not find the "Date"
field.
I'm sure this means I've named some object somewhere in my db "Date" but I
can't find it.
Is there some way of doing a search or listing all the objects by name so I
can find the offending piece and rename it?

In case you want to make sure my code is correct....

Private Sub Command10_Click()
BODDate.Locked = False
BeginTime.Locked = False
BODDate = Date
BeginTime = Now()
BeginTime.Locked = True
BODDate.Locked = True
Present = -1
End Sub

Any help would be appreciated.

Thanks,
poorboy13
 
K

KARL DEWEY

The problem is with this --- BODDate = Date

I do not do vba but try this --- BODDate = Date()
 
F

fredg

The problem is with this --- BODDate = Date

I do not do vba but try this --- BODDate = Date()

Karl,
In VBA (unlike in Access) there is no need to add the () to the Date
function. And if you did, the VBA editor would strip them away.

I would suspect that the user has a reference problem.

Open any module in Design view (or click Ctrl + G).
On the Tools menu, click References.
Click to clear the check box for the type library or object library
marked as "Missing:."

An alternative to removing the reference is to restore the referenced
file to the path specified in the References dialog box. If the
referenced file is in a new location, clear the "Missing:" reference
and create a new reference to the file in its new folder.

See Microsoft KnowledgeBase articles:
283115 'ACC2002: References That You Must Set When You Work with
Microsoft Access'
Or for Access 97:
175484 'References to Set When Working With Microsoft Access' for
the correct ones needed,
and
160870 'VBA Functions Break in Database with Missing References' for
how to reset a missing one.

For even more information, see
http://www.accessmvp.com/djsteele/AccessReferenceErrors.html
 
L

Linq Adams via AccessMonster.com

I agree with Fred, this is a fairly common problem and almost always a case
of a missing reference, and the VBA Editor will, indeed, strip the trailing
parens.
 
B

BruceM via AccessMonster.com

In addition to what has been suggested, look at the top of the code module.
If Option Explicit does not appear below Option Compare Database, add it,
then compile the code. If you had to add it, in the VBA editor go to ToolsThis is how to go about it in Access 2003. I'm not sure how it would be done
in later versions.

If you are adding values programatically I don't think there is a need to
unlock the controls. Also, I would add the Me. prefix:

Me.BODDate = Date

When you use the prefix, Access will look for BODDate only in the form's
properties (which includes fields and controls). Without the prefix Access
needs to resolve whether BODDate is a field, function, constant, variable,
property, or whatever. Also, the Me prefix followed by a dot presents you
with a pick list, which often saves time, and tends to reduce the possibility
of typos.
 
P

poorboy13 via AccessMonster.com

Thanks to all who responded - I appreciate it.
I did look through the References list in the VBA editor and could not find
anything that was "Missing".
I should mention I do have 2 other forms in the same DB with almost identical
code (with the exception of the actual field names) that work just fine.
Instead of BODDate = Date
It is StartDate = Date
and EndDate = Date
These work just fine.
But the form with BODDate = Date does not work.

I do find it odd that VBA looses the () and both Access and Excel (maybe Word
too I don't know) use Date() instead of Date. I have tried stuffing Date into
a formated variable and making BODDate = the variable, but it does the same
thing.

Any other suggestions?

I have back ups at various stages in the design, so I may just scrap it and
go back and redo this part but it is just somewhat baffling to say the least.
 
S

Stuart McCall

BruceM via AccessMonster.com said:
In addition to what has been suggested, look at the top of the code
module.
If Option Explicit does not appear below Option Compare Database, add it,
then compile the code. If you had to add it, in the VBA editor go to
Tools
This is how to go about it in Access 2003. I'm not sure how it would be
done
in later versions.

If you are adding values programatically I don't think there is a need to
unlock the controls. Also, I would add the Me. prefix:

Me.BODDate = Date

When you use the prefix, Access will look for BODDate only in the form's
properties (which includes fields and controls). Without the prefix
Access
needs to resolve whether BODDate is a field, function, constant, variable,
property, or whatever. Also, the Me prefix followed by a dot presents you
with a pick list, which often saves time, and tends to reduce the
possibility
of typos.

And when the object prefix (Me) is used, its memory address can be resolved
at compile-time, instead of at run-time, when it could slow things down.
Disambiguation is a Good Thing for all sorts of reasons.
 
B

BruceM via AccessMonster.com

What happens when you add Option Explicit and compile the code? Also, try
adding the Me prefix to BODDate, at least. I would name the control
something like txtBODDate to distinguish it from the field name. I doubt it
is the problem, but if you can resolve some of the ambiguities it may help
you sort out what is happening.

Assuming the code compiles, try placing a break point into the code. When
the code breaks, go to the immediate window and type:
?Date()
and press Enter.
 
P

poorboy13 via AccessMonster.com

Nothing. I tried the Option Explicit and compile and it shows no errors.
I added the Me.Prefix and changed the Control name. It still gives off the
same error.

With the break point, in the Immediate Window I get an Run-time error '2465'
and the same message of "...can not find the field 'Date' referred to in your
expression."

Thanks for your help!

What happens when you add Option Explicit and compile the code? Also, try
adding the Me prefix to BODDate, at least. I would name the control
something like txtBODDate to distinguish it from the field name. I doubt it
is the problem, but if you can resolve some of the ambiguities it may help
you sort out what is happening.

Assuming the code compiles, try placing a break point into the code. When
the code breaks, go to the immediate window and type:
?Date()
and press Enter.
Thanks to all who responded - I appreciate it.
I did look through the References list in the VBA editor and could not find
[quoted text clipped - 20 lines]
 
B

BruceM via AccessMonster.com

Please post the line of code at which the error occurs.
Nothing. I tried the Option Explicit and compile and it shows no errors.
I added the Me.Prefix and changed the Control name. It still gives off the
same error.

With the break point, in the Immediate Window I get an Run-time error '2465'
and the same message of "...can not find the field 'Date' referred to in your
expression."

Thanks for your help!
What happens when you add Option Explicit and compile the code? Also, try
adding the Me prefix to BODDate, at least. I would name the control
[quoted text clipped - 12 lines]
 
P

poorboy13 via AccessMonster.com

Here is the whole Sub
The specific line is
BODDate=Date

Private Sub Command10_Click()
BODDate.Locked = False
BeginTime.Locked = False
BODDate = Date
BeginTime = Now()
BeginTime.Locked = True
BODDate.Locked = True
Present = -1
End Sub
I do appreciate the help but in the interest of time I reverted back to older
version and re-wrote it all and it is working fine now.
I know at some point I named 2 objects "Date" (Not thinking, obviously) but
even though I renamed them after this problem presented itself, it never
fixed the problem. It is just curious that the forms I wrote before I named
those 2 objects continued to work after my mistake but any new creation with
that same code did not.

Please post the line of code at which the error occurs.
Nothing. I tried the Option Explicit and compile and it shows no errors.
I added the Me.Prefix and changed the Control name. It still gives off the
[quoted text clipped - 11 lines]
 
B

BruceM via AccessMonster.com

Did you try doing a Compact and Repair (Tools >> Database Utilities >>
Compact and Repair)? Back up the database first. Make sure you do this.
Really.

I'm guessing you have Name Autocorrect enabled. For more information:
http://allenbrowne.com/bug-03.html

It may be worthwhile going through this recovery sequence:
http://allenbrowne.com/recover.html
Here is the whole Sub
The specific line is
BODDate=Date

Private Sub Command10_Click()
BODDate.Locked = False
BeginTime.Locked = False
BODDate = Date
BeginTime = Now()
BeginTime.Locked = True
BODDate.Locked = True
Present = -1
End Sub
I do appreciate the help but in the interest of time I reverted back to older
version and re-wrote it all and it is working fine now.
I know at some point I named 2 objects "Date" (Not thinking, obviously) but
even though I renamed them after this problem presented itself, it never
fixed the problem. It is just curious that the forms I wrote before I named
those 2 objects continued to work after my mistake but any new creation with
that same code did not.
Please post the line of code at which the error occurs.
[quoted text clipped - 3 lines]
 

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