PDA

View Full Version : User Form HELP



Mykasd
10-16-2007, 10:41 AM
For some reason I cannot get my userform to populate selected variables.

Here is my code:

Private Sub OKButton_Click()
'Capture DM(s)
Dim i As Long, NDMs As Integer, DM() As String

NDMs = 0
For i = 0 To DMList.ListCount - 1
If DMList.Selected(i) = True Then
NDMs = NDMs + 1
ReDim Preserve DM(NDMs)
DM(NDMs) = DMList.List(i, 0)
End If
Next i
Unload Me
End Sub

A pop up is supposed to appear showing what the user selected, but this is blank:

'InputsForm user form appears here to prompt user to select DMs
InputsForm.Show
MsgBox "The user chose the following DM(s): " & vbLf _
& Join(DM, vbLf), vbInformation, "User Inputs"


Then I try to create a worksheet tab by each DM name and it doesn't work. Code is:

'Creates new tabs for each DM selected
For i = 1 To NDMs
'Deletes worksheets for DMs that already exist, if user selects same trait again
'Dim sht As Worksheet
For Each sht In Worksheets
If sht.Name = DM(i) Then sht.Delete
Next
'adds new worksheet
Sheets.Add.Name = DM(i)
Next i


Can someone please help solve this problem. I need to be able to select DMs, have a pop up come up and show which have been selected, then populate tabs named after each DM.

lucas
10-16-2007, 02:35 PM
Since no one has addressed this all day I will say it. Post your workbook so we can see what is going on.

mikerickson
10-16-2007, 05:07 PM
Just looking at your code, I'm not sure what you are trying to do. But, as written, the values of DM() are not avaliable to any routine other than the OKButton_Click sub.
I'd suggest removing the current Dim statement and putting this line at the top (outside of any routine) of a normal code module (not the Userform's code module).
Public DM() as StringThat will make the array DM avaliable to every routine in your project.

If that doesn't work, post the workbook.