public instead of dim not working (1 Viewer)

DKY

Registered User.
Local time
Today, 03:24
Joined
Mar 18, 2005
Messages
17
I'm trying to use public to declare a variable called 'NewStep' instead of dim. Here's the beginning of my code:
Code:
Option Compare Database
Option Explicit
Public Function CopyFilesFromR()
Dim strYourDestination As String, strFiles As String, strPath As String, StepTotal As String
Public NewStep As String
and it's not working
Compile error:
Invalid attribute in Sub or Function
Any suggestions?

Other sites I've asked this question on:
http://www.utteraccess.com/forums/s...89373&Zd=l&Zn=&Zt=108&Zs=&Zy=#Post1728692&Zp=
http://www.accessforums.net/showthread.php?p=2363#post2363
 

Kiwiman

Registered User
Local time
Today, 09:24
Joined
Apr 27, 2008
Messages
799
Howzit

Not sure if this is the right place to put it, but I put it before the Optoin Compare Database

Code:
Public NewStep As String
Option Compare Database
Option Explicit
Public Function CopyFilesFromR()
Dim strYourDestination As String, strFiles As String, strPath As String, StepTotal As String
 

dkinley

Access Hack by Choice
Local time
Today, 03:24
Joined
Jul 29, 2008
Messages
2,016
You pasted ...

Code:
Public Function CopyFilesFromR()
Dim strYourDestination As String, strFiles As String, strPath As String, StepTotal As String
Public NewStep As String

But you don't end the function ...

Code:
Public Function CopyFilesFromR()
Dim strYourDestination As String, strFiles As String, strPath As String, StepTotal As String
[COLOR=red]End Function[/COLOR]

Public NewStep As String

-dK
 

ByteMyzer

AWF VIP
Local time
Today, 01:24
Joined
May 3, 2004
Messages
1,409
No, dkinley, it's just that DKY did not post the entire function. However, that is not the real problem.

The REAL problem is that DKY declared a Public variable inside of a function. Public variables have to be declared outside of the function, like so:
Code:
Option Compare Database
Option Explicit

[b]Public NewStep As String[/b]

Public Function CopyFilesFromR()
Dim strYourDestination As String, _
    strFiles As String, _
    strPath As String, _
    StepTotal As String

'''''
' the rest of the function code here
'''''

End Function
 

dkinley

Access Hack by Choice
Local time
Today, 03:24
Joined
Jul 29, 2008
Messages
2,016
Ah okay ...

I was going to go to that next ... even go so far as to say ..

Option Compare Database
Public NewStep As String
Option Explicit

Public ....

-dK
 

DKY

Registered User.
Local time
Today, 03:24
Joined
Mar 18, 2005
Messages
17
putting the public before the Option Explicit and Optoin Compare Database works, thanks!
 

DKY

Registered User.
Local time
Today, 03:24
Joined
Mar 18, 2005
Messages
17
Is there something other than string that I can use to make the variable two digits minimum? It is involved in a loop and increments by one every time but when it's in the 1, 2,3 stage I would like it to display 01,02,03.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 01:24
Joined
Aug 30, 2003
Messages
36,126
As answered on your other thread:

Format(VariableName, "00")
 

DKY

Registered User.
Local time
Today, 03:24
Joined
Mar 18, 2005
Messages
17
As I just posted on the other thread:
That works but it looks like I have to do that every time I add to the variable

NewStep = NewStep + 1

has to now be changed to

NewStep = NewStep + 1
NewStep = Format(NewStep,"00")

I guess that will work.
 

Users who are viewing this thread

Top Bottom