Ian Chappel said:
I am however having trouble setting a variable's value in the calling
form. The variable is declared right after Option Explicit in the calling
form, and is a one-dimensional string array. Maybe I need to make the
variable Public, but I get an error when I do so. Or should I use a simple
public string variable - if so, what event could I use to assign it's
value to the array element?
yes, I did not realize the above. Ok, if you go
public Mystring as string
The above works.
And:
dim MyString(5) as string
The above works
however, public, such as:
Public MyString(5) as string
The above is NOT allowed. I did not know this (but hey that way I spend time
here in these newsgroups to learn!).
however, you can get around this:
You can simply build a set of custom property "gets" and "lets" for a form.
Remember, any pubic function of a forms module becomes a method, and also
that let/get are legal. The form is a basic class object.
So, just go:
Option Compare Database
Option Explicit
Dim buf(10) As String
Public Property Get Nbuf(i As Integer) As String
Nbuf = buf(i)
End Property
Public Property Let Nbuf(i As Integer, s As String)
buf(i) = s
End Property
The above will simply expose a public property called NBuf that lets I
get/let the value of buf().
So, then, you can go:
forms("myform").NBuf(1) = "abc"
or
debug.print forms("myform").NBuf(1)
--> abc
So, you can reference the array through a public property get/let....
if you don't need an arrary, then just public var name will work...