jasonhmann
New Member
- Joined
- Feb 5, 2007
- Messages
- 39
Hey Everyone,
Questions:
I would like to display to the user a listbox if I want the user to make a selection, otherwise I want to display only one value. The form I have created allows the user to edit tables, the form changes depending on what the user selects in the options menu. E.G. If the user selects update device number, I would like to change the textbox containing the device # to a list box containing all possible device #s.
My current code:
Cheers,
Jason
Questions:
- Is there a way to convert a textbox to a list box in code?
Is there a way to directly select a control from a string containing its name so that I may changes its properties, e.g. something like
Str = “DeviceNum”
Me.select(Str)
I would like to display to the user a listbox if I want the user to make a selection, otherwise I want to display only one value. The form I have created allows the user to edit tables, the form changes depending on what the user selects in the options menu. E.G. If the user selects update device number, I would like to change the textbox containing the device # to a list box containing all possible device #s.
My current code:
Code:
Private Sub dropdown(CaptionName As String, sSQL As String)
Dim rs As ADODB.Recordset
Dim sRow As String
Dim myCtl As Control
Dim tempLB As New ListBox
Set rs = New ADODB.Recordset
'Loop through each Control in the Current Form
For Each myCtl In Me.Controls
Select Case myCtl.ControlType
Case acTextBox, acComboBox, acListBox 'Control is a Text Box
If (myCtl.Value = "Hayes") Then 'Control is a Text Box
'Procesing code here
sRow = myCtl.Value
Set tempLB = myCtl.Object ‘ VBA doesn’t like my conversion here
With rs
.Open sSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
tempLB.RowSourceType = "Value List"
Do Until .EOF
If sRow = vbNullString Then
sRow = rs.Fields(1)
Else
sRow = sRow + ", " + rs.Fields(1)
End If
.MoveNext
Loop
.Close
tempLB.RowSource = sRow
End With
Exit Sub ' completed the search now exit sub
End If
Case Else
End Select
Next
End Sub
Cheers,
Jason