luke_t
luke_t

Reputation: 2985

Pass variable into button_click procedure

Is it possible to pass a variable into a button_click procedure?

Background:

I have 2 procedures, both of which perform some actions, and then both open Form_1. Now, dependant on which procedure opened Form_1, I want the command button to perform a different task with the data on the form. Ordinarily, I would pass a variable from the first procedure into the procedure being called.

However, due to it being a form being called, which requires the user to click the command button to initiate the second procedure, I do not think it's possible to pass a variable to this procedure?

For now I assign a public variable in procedure_1: override = False and procedure_2: override = True, but I know it's generally frowned upon to use public variables (from what I have read).

Within the button_click procedure I then use this variable to route the code accordingly.

Private Sub CommandButton1_Click()
    If override Then
        Call override_data
    Else
        Call submit_data
    End If
End Sub

Am I okay, in this scenario, to use a public variable? or is there a better way to achieve my target?

Upvotes: 2

Views: 2228

Answers (1)

luke_t
luke_t

Reputation: 2985

I ended up reading Jon Peltier's article on user form properties, as suggested in the comments by @PeterT.

This enabled me to use a user form property instead of a public variable.

Upvotes: 1

Related Questions