Reputation: 1
I have a FORM and MODULE in VBA. When the macro is run the form is displayed (frmQuestions), data is entered into a text box (txtName) and a pulldown (lstChoose). When the user presses the command button (cmdEnter), how can I pass the data in txtName and lstChoose to the module?
Upvotes: 0
Views: 1693
Reputation: 15058
To pass data from an event on a form to a function contained in a module do something like the following:
The On Click event code contained within frmQuestions
form:
Private Sub cmdEnter_Click()
Dim TempReturnVal as Boolean
TempReturnVal = funUpdateRecords(txtName.value, lstChoose.value)
End Sub
Function in Module:
Public Function funUpdateRecords(funName As String, funChoice As String) As Boolean
' Do whatever it is that you want to
'funName contains the value of txtName
'funChoice contains the value of lstChoose
'Return True if successful or False if not.
funUpdateRecords = True
End Function
Upvotes: 1