Property let

S

swas

Hi,

Is it possible to pass more than one value to a form property let statement?
For example, can I have a form with a property:

Property Let SetControl (srtA as string, strB as string)

'Code to process

End Property

If I only have a single parameter it works fine, but if I have two as shown
bombs when setting from code, eg:

Forms!frmWithProperty.SetControl = "ABCD", "DEFG" 'Doesn't work

Forms!frmWithProperty.SetControl ("ABCD", "DEFG") 'Doesn't work

Or does this need to be done with arrays?

Examples or advice appreciated.


swas
 
B

Brendan Reynolds

You could use an array, something like so ...

Option Compare Database
Option Explicit

Private mvarValues() As Variant

Public Property Let TestProp(values As Variant)

If IsArray(values) Then
mvarValues = values
Else
ReDim mvarValues(0)
mvarValues(0) = values
End If

End Property

Forms("frmTest2").TestProp = "one"
Forms("frmTest2").TestProp = Array("one", "two")

It might be simpler to just implement the procedure as a method instead of a
property, though?
 
S

swas

Brendan,

Now there's a funny thing... I wanted to use a method but I seem to be
having the same problem.

Public Sub SetControl (strA As String, strB As String)

'Code here

End Sub

If I call this with

Forms!frmWithMethod.SetControl ("ABCD", "DEFG")

I get the same error, yet works fine if there is only one parameter

I haven't done programming for a couple of years, and then self taught.
Acess 2000 help seems 10 times better than 2003 - you can get examples
etc... to read through. 2003 seems to be the strict reference only, or very
brief examples. Same with MSDN - all the vba expanded help seems to have
disappeared - since .net is on the scene?

Thanks for your thoughts.


swas
 
B

Brendan Reynolds

I haven't tested this, but from memory that would need to be either ...

Forms!frmWithMethod.SetControl "ABCD", "DEFG"

.... (note no parentheses) or else ...

Call Forms!frmWithMethod.SetControl("ABCD", "DEFG")

.... (note use of 'Call' keyword when calling procedure with arguments
enclosed in parentheses).
 
Top