Having issues with For Each when string array is passed as a method/sub argument in a macro

Hello everyone

My objective: Parse all controls within the masterform/subform and set the visibility property except these ones defined in a string array.

My solution: Create a recursive function which takes as argument a form, the list of the excluded form names and the visibility flag.

My problem: When passing the string array to the recursive function I get an BASIC runtime error “Object Value not set.”

I wrote the simplified code below which gives the same error when the For Each-codeblock in the recursive function is called. There’s no issue with same For Each-codeblock in the Test() function.

I believe there’s an issue how I pass the string array as it is not initialised in the recursive function.

Many thanks upfront for helping me solving the issue.

Sub test 
    str_array =   array("Form1", "form2", "form_3") 
     For each entry in str_array
         msgbox entry
     Next 
 iterate( str_array )
End Sub    

sub iterate( something as variant )  'your argument is NOT a string'
	for each entry in something
		msgbox entry & " from iterator"
	next
end sub

Hey, thanks for mentioning the reason. What’s the solution? Is there a way to declare the Array() as string array? Something like that?

Dim aMyStringArray() As String
aMyStringArray = Array("form1","form2","form3","form4") As String

or do I need to use the explicit form:

Dim aMyStringArray(3) As String
aMyStringArray(0) = "form1"
aMyStringArray(1) = "form2"
aMyStringArray(2) = "form3"
aMyStringArray(3) = "form4"

I would say »yes« … but dont ask me about the secrets of BASIC … (I would use python)

Replace
Sub ForEachSub(MyForms() as String)
with
Sub ForEachSub(MyForms() as Variant)

that was already said:

Thank you both for your help. Learned something new.