Passing 'FormReference' arguments.

Robert Burns

Registered User.
Local time
Today, 09:42
Joined
Jul 1, 2002
Messages
14
Hi there,

I am trying to pass some arguments from a form's code module in a call to a public procedure stored in a standard code module. The arguments I am passing are:

'strFormName" the name of the form, which = "frmFilter"
'strList' the name of a list box, which = "lstFiltered"

Why, when I try to reference the list box in the public procedure by:

If Forms!strFormName!strList.ItemsSelected.Count = 0 Then

do I receive the message that 'strFormName cannot be found'?

If I replace the variables in the public procedure with the full reference notation, then it works fine, so I assume that something is wrong with my passing in the arguments. I have tried many variations with no success,

Any help much appreciated,

Rob
 
The code is looking for the forms 'strFormName' and 'strList' which are the variable names.
You need to reference it something like:

If "Forms!" & strFormName & "!" & strList & ".ItemsSelected.Count" = 0 Then
Haven't tested it, but it would be something along those lines.

PS Is there a problem with referencing the full path as you suggested works. Thats what I do, mainly so it is easier to track where variables are coming from.
HTH
Dave
 
Cheers Dave for your help,

I am trying your syntax but it says that there is now a 'type mismatch' .

I don't think I can use the full reference version because I am trying to create a shared procedure that reads the selected contents of a list box, generates a WHERE string, and then opens a form accordingly. This procedure will be called by various forms, thus I am trying to pass the required arguments from each, procedure.

Rob
 
I'm sure some one will correct the code I posted. My need brackets or something.

Sure you will get it going eventually.
Dave
 
Code:
Public Function GetCount(stFormName As String, stListBox As String) As Integer
GetCount = Forms(stFormName).Form.Controls(stListBox).ListCount

End Function
 
Thanks very much Travis,

That seems to have sorted it.

Cheers,
Rob
 
Travis I have never heard of GetCount.
Can you explain its use
Dave
 
"GetCount" is a Custom made Function. This is one of the Advantages to VBA, you can create a Complicated Calculation and call it from anywhere.
 

Users who are viewing this thread

Back
Top Bottom