Public date variable

B

Brian

I have a standalone module (i.e. not behind a form) that has these two
variables (among many others) in its declarations section:

Option Explicit
Public Date1 As Date
Public Boolean1 As Boolean

(Not their real names, obviously.) I set the value of these variables in a
Public Function within that module, like this:

Public Function TestFunction()
Date1 = Date
Boolean1 = True
End Function

When I call the function from a sub on a form, Boolean1 returns True, but
Date1 returns Null. Why?

Private Sub Test()
TestFunction
MsgBox Boolean1 'returns "True"
MsgBox Nz (Date1,"Null") 'returns N'"Null"
End Sub
 
D

Dirk Goldgar

Brian said:
I have a standalone module (i.e. not behind a form) that has these two
variables (among many others) in its declarations section:

Option Explicit
Public Date1 As Date
Public Boolean1 As Boolean

(Not their real names, obviously.) I set the value of these variables
in a Public Function within that module, like this:

Public Function TestFunction()
Date1 = Date
Boolean1 = True
End Function

When I call the function from a sub on a form, Boolean1 returns True,
but Date1 returns Null. Why?

Private Sub Test()
TestFunction
MsgBox Boolean1 'returns "True"
MsgBox Nz (Date1,"Null") 'returns N'"Null"
End Sub

It works fine for me. I wonder if you have a public variable or control
named "Date", so that the statement
Date1 = Date

.... is actually assigning the value of that variable or control, and not
the value of the built-in function Date().
 
B

Brian

Shame on me.

I had originally started this process using an invisible text box of the
same name. When I just returned to this project after a couple of weeks of
other things, I forgot about that & restarted the process using a public
variable instead.

Then, when I searched for the obvious sources of conflict, I forgot about
the control name and searched just VBA for variable name conflicts!

Inexcusable blunder on my part, and a little tunnel vision to boot. Thanks
for the reminder. It got me out of my tunnel.
 

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