Compile Error:Variable not defined.

  • Thread starter Thread starter DaveB
  • Start date Start date
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?
 
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.
 
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
 
Back
Top