Invalid Outside Procedure (Date, Time, Format, etc...)

O

Olda

Hi,

I have just install new version MS Office 2007, but I have problems with
internal functions (Date, Time, Format, etc...):

Option Explicit
Dim MyDate
MyDate = Date ' MyDate contains the current system date.

When I compile this code, system return error "Invalid Outside Procedure".

Can you help me?

Thank you, Olda
 
M

Marshall Barton

Olda said:
I have just install new version MS Office 2007, but I have problems with
internal functions (Date, Time, Format, etc...):

Option Explicit
Dim MyDate
MyDate = Date ' MyDate contains the current system date.

When I compile this code, system return error "Invalid Outside Procedure".


That correct. Code only executes when it is called from
some other code procedure or when an event is triggered.

You need enclose that line in Function, End Function or Sub,
End Sub statements. Then you have to call the function or
sub from somewhere.
 
K

Ken Snell \(MVP\)

You must have a Sub or Function into which to put those code steps. They can
exist outside of a procedure (Sub or Function). For example, if you wanted
to run that code in the Load event of a form:

Option Explicit

Private Sub Form_Load()
Dim MyDate As Date
MyDate = Date
End Sub
 

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