Userform Not working PLEASE HELP

B

Bishop

I have created a dialog box (NotSoFast) to pop up when my workbook is opened.
The dialog box has 4 comboboxes (Name, Center, Month, Week) each of which
I've created data for, and a button (Panic Switch) which captures the data.
My dialog box shows when the workbook is opened but there's no data in any of
my combobox lists. What is causing this? Below is my code:

Auto_open code
Private Sub Workbook_Open()
NotSoFast.Show
End Sub
---------------------------------------------------------
command button code
Private Sub PanicSwitch_Click()
MonthSelect = Month.Value
WeekSelect = Week.Value
NameSelect = Name.Value
CenterSelect = Center.Value
Cells(1, 1) = MonthSelect
Cells(2, 1) = WeekSelect
Cells(1, 2) = NameSelect
Cells(2, 2) = CenterSelect
Unload NotSoFast
End Sub
---------------------------------------------------------
module code for the comboboxes
Public NameSelect As String
Public CenterSelect As String
Public MonthSelect As String
Public WeekSelect As String

Sub ShowNotSoFast()
With NotSoFast.Name
.RowSource = ""
.AddItem "Bishop Minter"
.AddItem "Carlos Trespalacios"
.AddItem "Dennis Murphy"
.AddItem "Gary Hayden"
.AddItem "Gloria Montoya"
.AddItem "Lisa Muttillo"
.AddItem "Lorraine Warburton"
.AddItem "Warner Langlois"
End With
With NotSoFast.Center
.RowSource = ""
.AddItem "Bothell"
.AddItem "Collinsville"
.AddItem "El Paso"
.AddItem "Evansville"
.AddItem "Greensboro"
.AddItem "Heathrow"
.AddItem "Joplin"
.AddItem "Kennesaw"
.AddItem "Lafayette"
.AddItem "Manhattan"
.AddItem "Mansfield"
.AddItem "Sioux City"
.AddItem "Ottawa"
.AddItem "Ponco City"
.AddItem "Terra Haute"
End With
With NotSoFast.Month
.RowSource = ""
.AddItem "January"
.AddItem "February"
.AddItem "March"
.AddItem "April"
.AddItem "May"
.AddItem "June"
.AddItem "July"
.AddItem "August"
.AddItem "September"
.AddItem "October"
.AddItem "November"
.AddItem "December"
End With
With NotSoFast.Week
.RowSource = ""
.AddItem "Week 1"
.AddItem "Week 2"
.AddItem "Week 3"
.AddItem "Week 4"
.AddItem "Week 5"
End With
NotSoFast.Show
End Sub
---------------------------------------------------------
Also, the code will not compile unless I comment out anything pertaining to
Name. I get a "Compile Error: With object must be user-defined type, Object
or Variant" with the first With statement under Sub ShowNotSoFast(). If I
comment out that entire With Block I get a "Compile Error: Invalid Qualifier"
for Name in the NameSelect = Name.Value line under Private Sub
PanicSwitch_Click(). If I comment out both of those the code compiles. I've
retyped Name in Properties for the combobox and that didn't fix it. What's
the problem?
 
B

Bishop

I changed "Name" to "NameC" and that corrected both of my compile errors so
disregard that part (I assume "Name" is a keyword?). Still can't get the
drop-downs to populate though.
 
J

JLGWhiz

This line would be included in a procedure somewhere in Module1 or if you
have more than one public code module then whichever you are using. You can
also as a Sub title line and an End Sub line and use it as a stand alone
procedure.

NotSoFast.Show


This code (yours slightly modified) goes behind your UserForm dialog box.
Right click on the form or double click it in design mode and copy this into
the form code module. When you run the Show command from the public module,
it will activate the initialize event and it should load your comboboxes.

Private Sub NotSoFast_Initialize()
With Me.Name
.RowSource = ""
.AddItem "Bishop Minter"
.AddItem "Carlos Trespalacios"
.AddItem "Dennis Murphy"
.AddItem "Gary Hayden"
.AddItem "Gloria Montoya"
.AddItem "Lisa Muttillo"
.AddItem "Lorraine Warburton"
.AddItem "Warner Langlois"
End With
With Me.Center
.RowSource = ""
.AddItem "Bothell"
.AddItem "Collinsville"
.AddItem "El Paso"
.AddItem "Evansville"
.AddItem "Greensboro"
.AddItem "Heathrow"
.AddItem "Joplin"
.AddItem "Kennesaw"
.AddItem "Lafayette"
.AddItem "Manhattan"
.AddItem "Mansfield"
.AddItem "Sioux City"
.AddItem "Ottawa"
.AddItem "Ponco City"
.AddItem "Terra Haute"
End With
With Me.Month
.RowSource = ""
.AddItem "January"
.AddItem "February"
.AddItem "March"
.AddItem "April"
.AddItem "May"
.AddItem "June"
.AddItem "July"
.AddItem "August"
.AddItem "September"
.AddItem "October"
.AddItem "November"
.AddItem "December"
End With
With Me.Week
.RowSource = ""
.AddItem "Week 1"
.AddItem "Week 2"
.AddItem "Week 3"
.AddItem "Week 4"
.AddItem "Week 5"
End With
End Sub
 
B

Bishop

Didn't work. I copy/pasted your code just as you instructed. Everything is
working EXCEPT my comboboxes have no drop downs. I set the Matchrequired
field to True and the only thing that doesn't return an error is leaving the
field blank which is making me think the initialization process isn't taking
place at all. The Command Button works perfectly. Whatever info I put in
the boxes populates the correct cells but since my comboboxes aren't
initialized with the data I want you can put whatever you like in the
combobox field and it will take it. Why aren't my comboboxes populating?! I
also tried the method described here:
http://www.contextures.com/xlUserForm02.html
and that still doesn't work! Here is my code:

behind the userform (NotSoFast)
Private Sub PanicSwitch_Click()
MonthSelect = Month.Value
WeekSelect = Week.Value
NameSelect = AName.Value
CenterSelect = Center.Value
Cells(1, 1) = MonthSelect
Cells(2, 1) = WeekSelect
Cells(1, 2) = NameSelect
Cells(2, 2) = CenterSelect
Unload NotSoFast
End Sub
____________________________________

Private Sub NotSoFast_Initialize()
Dim cAName As Range
Dim cCenter As Range
Dim cMonth As Range
Dim cWeek As Range
Dim ws As Worksheet
Set ws = Worksheets("X")

For Each cAName In ws.Range("AName")
With NotSoFast.AName
.AddItem cAName.Value
.List(.ListCount - 1, 1) = cAName.Offset(0, 1).Value
End With
Next cAName

For Each cCenter In ws.Range("Center")
With Me.Center
.AddItem cCenter.Value
.List(.ListCount - 1, 1) = cCenter.Offset(0, 1).Value
End With
Next cCenter

For Each cMonth In ws.Range("Month")
With Me.Month
.AddItem cMonth.Value
.List(.ListCount - 1, 1) = cMonth.Offset(0, 1).Value
End With
Next cMonth

For Each cWeek In ws.Range("Week")
With Me.Week
.AddItem cWeek.Value
.List(.ListCount - 1, 1) = cWeek.Offset(0, 1).Value
End With
Next cWeek

End Sub

I have created the appropriate lists on sheet X as per the instructions.
Surely, it must be something simple that I'm missing... help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top