Listbox selection creates form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Hello,
Here is a new one. I have a userform with one listbox(lstTreatment) and a
button(cmdSelect). I have it set up so the user can select multiple
selections in the listbox.

Next, I have created another userform that has a text box for the RFID when
scanned, then there are 10 lables (label1, label2, etc.)

Problem: I would like the selections choosen from the 1st userform to fill
the labels in the second userform. Soooo . . . if the user selects from the
listbox:
1. Vaccinate
2. Deworm
Those two selections will be the names of label1 and label2.

I hope this makes sense! Thanks guys!

Anyone have any recommendations on classes or great books on learning FoxPro?
 
Jennifer,
On the first form, with your listbox and cmdSelect:

Private Sub UserForm_Initialize()
With ListBox1
.AddItem "Vaccinate"
.AddItem "Deworm"
.AddItem "Neuter"
.AddItem "Inseminate"
.AddItem "Put Down"
End With

End Sub

Private Sub cmdSelect_Click()
Dim i As Long
Dim SelCount As Long

With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
SelCount = SelCount + 1
UserForm2.Controls("Label" & SelCount).Caption = .List(i)
End If
Next
End With

UserForm2.Show

End Sub

UserForm2 has 10 labels called "Label1" ~ "Label10", with some default
caption of "Not set" or blank.
You should add some error trapping/checking that the number of options in
the list box does not exceed the number of available labels.

NickHK
 
Nick,
I am getting an and error "could not find specified object"
it then highlights this part of the code:
UserForm2.Controls("Label" & SelCount).Caption = .List(i)

Thank you so much for your help.
--
Though daily learning, I LOVE EXCEL!
Jennifer


NickHK said:
Jennifer,
On the first form, with your listbox and cmdSelect:

Private Sub UserForm_Initialize()
With ListBox1
.AddItem "Vaccinate"
.AddItem "Deworm"
.AddItem "Neuter"
.AddItem "Inseminate"
.AddItem "Put Down"
End With

End Sub

Private Sub cmdSelect_Click()
Dim i As Long
Dim SelCount As Long

With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
SelCount = SelCount + 1
UserForm2.Controls("Label" & SelCount).Caption = .List(i)
End If
Next
End With

UserForm2.Show

End Sub

UserForm2 has 10 labels called "Label1" ~ "Label10", with some default
caption of "Not set" or blank.
You should add some error trapping/checking that the number of options in
the list box does not exceed the number of available labels.

NickHK
 
Oops I figured it out. The problem was that I had another label for the RFID
text box and one for the date. So now my question is how can I have these
other two lables and it fill the label1>label10.

It just never ends! Ha!
--
Though daily learning, I LOVE EXCEL!
Jennifer


NickHK said:
Jennifer,
On the first form, with your listbox and cmdSelect:

Private Sub UserForm_Initialize()
With ListBox1
.AddItem "Vaccinate"
.AddItem "Deworm"
.AddItem "Neuter"
.AddItem "Inseminate"
.AddItem "Put Down"
End With

End Sub

Private Sub cmdSelect_Click()
Dim i As Long
Dim SelCount As Long

With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
SelCount = SelCount + 1
UserForm2.Controls("Label" & SelCount).Caption = .List(i)
End If
Next
End With

UserForm2.Show

End Sub

UserForm2 has 10 labels called "Label1" ~ "Label10", with some default
caption of "Not set" or blank.
You should add some error trapping/checking that the number of options in
the list box does not exceed the number of available labels.

NickHK
 
Jennifer,
Not sure what you mean.
This fills your labels with the required captions and I assumed the user
would enter the RFID and date.
If not, then where is this info coming from ?

NickHK

Jennifer said:
Oops I figured it out. The problem was that I had another label for the RFID
text box and one for the date. So now my question is how can I have these
other two lables and it fill the label1>label10.

It just never ends! Ha!
 
No your right Nick about the labels . . . but , at the top of the form across
the top I have a txtbox for the date and the scanned RFID but I have used a
label that says "Date" and "RFID" so the user know were to enter the date or
scan the RFID.

Hmmm hope that made sense. Jennifer
 
Jennifer,
So it all OK now ?

NickHK

Jennifer said:
No your right Nick about the labels . . . but , at the top of the form across
the top I have a txtbox for the date and the scanned RFID but I have used a
label that says "Date" and "RFID" so the user know were to enter the date or
scan the RFID.

Hmmm hope that made sense. Jennifer
 
Back
Top