I'm new to VBA and and am trying to finish this project by teaching myself. I'm trying to make a userform with a ComboBox drop down menu of months and a textbox to enter the year. I then want to have those values saved as variables and transferred back to the main module. I have referenced Assigning a variable directly from a userform and Passing variable from Form to Module in VBA, but what they did isn't working for me. This is what my form looks like.
My form is named Dates. The Combo box is Correct_Month; textbox is Correct_Year. I want to save these values in variables Month and Year.
This is what I have for the userform:
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub Correct_Month_Change()
Month = Correct_Month.Value
End Sub
Private Sub Correct_Year_Change()
Year = Correct_Year.Value
End Sub
Private Sub OkButton_Click()
'Message box forces a response
If Correct_Month.Text = "" Or Correct_Year.Value = "" Then
MsgBox ("You must enter a month and year to continue")
Exit Sub
End If
Unload Me
End Sub
Private Sub UserForm_Initialize()
Correct_Month.Clear
Correct_Month.List = Array("January", "February", "March", "April", "May", _
"June", "July", "August", "September", "October", "November", _
"December")
Correct_Year.Value = ""
End Sub
This is my module:
Private Sub Monthly_Report_Test()
'~~> more coding
Dates.Show
'something here to call variables over?
driver.findElementByName("Dates").SendKeys Month
driver.findElementByName("Dates").SendKeys Year
Correct_Info = MsgBox("Is the following information correct?" & vbCrLf & vbCrLf & _
"Report Month: " & Month & vbCrLf & vbCrLf & "Report Year: " & Year, _
vbYesNoCancel, "Month & Year")
If Correct_Info = vbCancel Then
Exit Sub
End If
'~~> more coding
End Sub
I've tried several different things and this is as close as I can get. Can anyone tell me what I need to do and why? Thank you so much!