1

I've been working on this problem for hours now, so I'll really appreciate any answers.

I have a userform with three buttons and I like them to pass a value, so I can use that value in my main module and depending on the value, run a specific code. I searched everywhere but they all pass values from textboxs

Here is my userform code:

private sub cancelButton_Click()
    response = 1
    UserForm1.Hide
End Sub

private Sub SutunButton_Click()
    response = 2
    UserForm1.Hide
End Sub

private Sub TirButton_Click()
    response = 3
    UserForm1.Hide
End Sub

and this is my main module:

public response as integer
sub example()
.
.
.
userform1.show
if response=1 then
msgbox "1"
elseif response = 2 then
msgbox "2"
elseif response = 3 then
msgbox "3"
end if
.
.
.
end sub

Of course I put msgbox to make my code simple.

Thanks for any help

1 Answer 1

1

Remove the global. To the module add:

Public Sub process(form As UserForm1, response As Integer)
    form.Hide

    Select Case response
        Case 1: MsgBox 1
        Case 2: MsgBox 2
        Case 3: MsgBox 3
    End Select
End Sub

Change the events to:

private Sub SutunButton_Click()
    process Me, 2
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the reply :) but it seems that "process" is not recognized as a function or a sub. what's the problem?!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.