Compile Error:Variable not defined.

D

DaveB

This is my VB.

Private Sub CityName_LostFocus()
'Copy the CompletionDateTime to Date
If IsNull(Date) Or Len(Date) = 0 Then
Me!Date = (CompletionDateTime)
End If
End Sub

But when I try to run it I get, "Compile Error:Variable
not defined". How can I make it automatically fill in the
(CompletionDateTime) into the (Date) field, and what is
wrong with my VB?
 
M

Mark Reed

Dave,


Seems to me that you haven't defined the variable CompletionDateTime. If
CompletionDateTime is a control on your form then you will need to reference
it i.e Me.CompletionDateTime.

If CompletionDateTime isn't a control the you will need to define it, use
Dim CompletionDateTime as Date. I also don't see a statement setting the
value for CompletionDateTime if it isn't a control.

I can't help further without seeing more of what's going on. Hope this can
get you started down the right route though.

Mark. mcse.
 
M

MacDermott

I don't know whether this will solve your problem, but it's generally a
rather bad idea to name anything in your database Date. Access uses this
keyword to return the current date, so trying to use it for another purpose
can easily cause confusion.

HTH
- Turtle
 

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