JBBennett
Technical User
- Jul 31, 2012
- 6
I need to query a database and build a multi-page form based on the data I find. I am working on the last page which is a list of names and what was done with them. To pass the data to the form, I am using a property and doing all the add control work in the property (since I could not figure out a way to get the data out of the property and into the form):
Public Property Let Names(ByVal strNames As String)
End Property
This builds the form quite well. But when I get back into my main program and try to utilize the choices from the list boxes, they do not work. I stepped through the code and used message boxes and determined the value of the list boxes are all blank.
For Each objNames In frmQuestions.MultiPage1("pg1").Controls
I tried switching to CheckBoxes but had no success at all building the form (basic parameters like Top and Caption could not be set). I am at a loss as to how to get the values in the list boxes to be passed out of form after OK is clicked.
Please help.
Jason Bennett
Public Property Let Names(ByVal strNames As String)
' Declare variables.
Dim lblName() As Label
Dim lstChoice() As ListBox
For intCounter = 1 To intNameCount
Dim lblName() As Label
Dim lstChoice() As ListBox
For intCounter = 1 To intNameCount
ReDim lblName(1 To intCounter)
ReDim lstChoice(1 To intCounter)
Dim strCurrentName As String
Set lblName(intCounter) = Me.MultiPage1("pg1").Controls.Add("Forms.Label.1")
Set lstChoice(intCounter) = Me.MultiPage1("pg1").Controls.Add("Forms.ListBox.1")
' Add labels with the names.
With lblName(intCounter)
' Add list boxes with the choices.
With lstChoice(intCounter)
intLabelTop = intLabelTop + 28
NextReDim lstChoice(1 To intCounter)
Dim strCurrentName As String
Set lblName(intCounter) = Me.MultiPage1("pg1").Controls.Add("Forms.Label.1")
Set lstChoice(intCounter) = Me.MultiPage1("pg1").Controls.Add("Forms.ListBox.1")
' Add labels with the names.
With lblName(intCounter)
.Caption = strCurrentName
.Top = intLabelTop
.Left = 6
.Height = 23
.Width = 80
.BorderStyle = fmBorderStyleSingle
.Name = "lblName" & intCounter
End With.Top = intLabelTop
.Left = 6
.Height = 23
.Width = 80
.BorderStyle = fmBorderStyleSingle
.Name = "lblName" & intCounter
' Add list boxes with the choices.
With lstChoice(intCounter)
.Top = intLabelTop
.Left = 90
.Height = 23
.Width = 150
.AddItem ("Choice used.")
.AddItem ("Choice *NOT* used.")
.Name = "lstChoice" & intCounter
End With.Left = 90
.Height = 23
.Width = 150
.AddItem ("Choice used.")
.AddItem ("Choice *NOT* used.")
.Name = "lstChoice" & intCounter
intLabelTop = intLabelTop + 28
End Property
This builds the form quite well. But when I get back into my main program and try to utilize the choices from the list boxes, they do not work. I stepped through the code and used message boxes and determined the value of the list boxes are all blank.
For Each objNames In frmQuestions.MultiPage1("pg1").Controls
Select Case Left(objNames.Name, 7)
NextCase "lblName"
strChoice = Replace(objNames.Name, "lblName", "")
If frmQuestions.Controls("lstChoice" & strChoice).Value = "Choice used." Then
End SelectstrChoice = Replace(objNames.Name, "lblName", "")
If frmQuestions.Controls("lstChoice" & strChoice).Value = "Choice used." Then
strNames = strNames & objNames.Caption
ElsestrNonNames = strNonNames & objNameds
End IfI tried switching to CheckBoxes but had no success at all building the form (basic parameters like Top and Caption could not be set). I am at a loss as to how to get the values in the list boxes to be passed out of form after OK is clicked.
Please help.
Jason Bennett