Hi,
I have a sub that opens a userform and displays a combobox containing the 12 month names. The user chooses the correct month name then this should be passed back to the calling sub as variable iPeriod.
My problem is, I cannot seem to pass the combobox value back to the calling sub. I'm a bit of a newbie and suspect there is an easy answer to this. Can anyone advise where I may be going wrong?
I've included some lines of code so you can get some idea of what I mean.
Any advice will be greatly appreciated,
Roy
Module:
Sub convWestMiddlesex()
'dims
frmChooseMonth.Show
iPeriod = frmChooseMonth.cmbChooseMonth.Text
etc.
etc.
end sub
userform:
Option Explicit
Private Sub cmdCancel_Click()
Unload Me
End Sub
Public Sub cmdOK_Click()
Dim i As Range
Dim iResult As String
Dim iPeriod As String
iResult = cmbChooseMonth.Value
If iResult > "" Then
With Worksheets("Lists").Range("L_April")
Set i = .Find(iResult, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows)
If Not i Is Nothing Then
iPeriod = i.Offset(0, 2).Value
End If
End With
Me.Hide
Unload Me
Else
Call frmChooseMonth_Initialize
End If
End Sub
Private Sub frmChooseMonth_Initialize()
cmbChooseMonth.Clear
End Sub
I have a sub that opens a userform and displays a combobox containing the 12 month names. The user chooses the correct month name then this should be passed back to the calling sub as variable iPeriod.
My problem is, I cannot seem to pass the combobox value back to the calling sub. I'm a bit of a newbie and suspect there is an easy answer to this. Can anyone advise where I may be going wrong?
I've included some lines of code so you can get some idea of what I mean.
Any advice will be greatly appreciated,
Roy
Module:
Sub convWestMiddlesex()
'dims
frmChooseMonth.Show
iPeriod = frmChooseMonth.cmbChooseMonth.Text
etc.
etc.
end sub
userform:
Option Explicit
Private Sub cmdCancel_Click()
Unload Me
End Sub
Public Sub cmdOK_Click()
Dim i As Range
Dim iResult As String
Dim iPeriod As String
iResult = cmbChooseMonth.Value
If iResult > "" Then
With Worksheets("Lists").Range("L_April")
Set i = .Find(iResult, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows)
If Not i Is Nothing Then
iPeriod = i.Offset(0, 2).Value
End If
End With
Me.Hide
Unload Me
Else
Call frmChooseMonth_Initialize
End If
End Sub
Private Sub frmChooseMonth_Initialize()
cmbChooseMonth.Clear
End Sub