PDA

View Full Version : Sleeper: Choosing formula in combobox



filex_id
08-03-2005, 08:28 PM
hi all http://www.ozgrid.com/forum/images/smilie/smile.gif
got some problem example i got 2 items in my combobox i name it as "countryA" at the top and "countryB" buttom which is in userform1.i created another form as userform2.when i choose countryA in userform1 and
i wanna call out countryA formula with a command button name it as "Export" but having some problem the msgbox keep having "countryB" chosen.can any one help thx

here is my code:


Private Sub CommandButton1_Click()
'Verify that an item was selected
If Me.ComboBox1.BoundValue = vbNullString Then
MsgBox "Please Choose A Formula!", vbOKOnly
Exit Sub
Else
If ComboBox1.ListIndex = 0 Then
MsgBox "Please Choose CountryA File To Open", vbOKOnly
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to import", _
FileFilter:="Excel Files *.xls (*.xls),")
Workbooks.Open FileName:=FileToOpen
Unload Me
UserForm2.Show
Else: ComboBox1.ListIndex = 1
MsgBox "Please Choose countryB File To Open", vbOKOnly
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to import", _
FileFilter:="Excel Files *.xls (*.xls),")
Workbooks.Open FileName:=FileToOpen
Unload Me
UserForm2.Show
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Error!!!"
Exit Sub
Else
End If
End If
End If
End Sub

Private Sub UserForm_Initialize()
With Me.ComboBox1
.AddItem ("CountryA")
.AddItem ("CountryB")
End With
End Sub

Sub Choose_Formula()
If userform1.ComboBox1.ListIndex = 0 Then
Call countryA_export
MsgBox "countryA chosen"
Else
Call countryB_export
MsgBox "countryB chosen"
End If
End Sub

Jacob Hilderbrand
08-22-2005, 07:52 PM
You are unloading UserForm1, but then you want to check the ListIndex from a control on UserForm1. Once it is unloaded it is released from memory so you can't get any of the data from it.

You can hide the UserForm if you want: UserForm1.Hide

filex_id
08-23-2005, 02:34 AM
thx for the reply :)