Posts by kayhan

    Re: Pass Userform as argument to a subroutine

    I will try what you've suggested.

    In the meanwhile i've found a workaround for this situation that allows me to do what what I intend to do. I've created a command button inside the Userform code module.

    With TempForm.CodeModule
            .InsertLines .CountOfLines + 1, "Private Sub " & "CommandButton3" & "_Click()"
            .InsertLines .CountOfLines + 1, "Call GetElecInfoFromUserForm(Me)"
            .InsertLines .CountOfLines + 1, "End Sub"
    End With

    Sub GetElecInfoFromUserForm(Myform As UserForm)
    End Sub

    Maybe it's not not the correct way to do this, but it works.
    If you have any suggestions I will apreciate. Thanks for the help Rory :)

    Re: Pass Userform as argument to a subroutine

    You're probably right Rory.

    Here's an example of what's inside GetElecInfoFromUserForm:

    For i = LBound(ElecArr, 1) To UBound(ElecArr, 1)
        For Each cCont In Myform.Controls
       aux = "ElecNameTextBox" & CStr(i)
       If TypeName(cCont) = "TextBox" Then
          If cCont.Name = aux Then
             ElecArr(i, 1) = cCont.Text
          End If
       End If
    Next i

    Basically what I want to do is:
    - Create a userform with code (Userform has a variable number of textboxes),populated with values from a worksheet
    - View the form and possibly change some values
    - Save the changes to the Worksheet

    Hi everyone,

    I'm doing a project and found a little problem (I'm very new to vba).
    I'm trying topass a userform as an argument to another subroutine, but I can't seem to do it correctly. (Run-time error '438'. Object doesn't support this property or method)

    Sub to create the userform:


    Sub GetElecInfoFromUserForm(ByRef Myform as Object)
    End sub

    Thanks in advance