Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Name of Combobox on a form

Status
Not open for further replies.

collib

Programmer
Oct 18, 2002
14
CA
I am trying to write a function that passes name on the current form and then loads a combobox on that form with names from a table in the DB.

If frmName.Controls = combox Then
cboName.Name = frmName.Controls.Name
End If
or something like this

Do Until mrst.EOF
strName = mrst.Fields(3) + ", " + mrst.Fields(4)
frmName.cboName.AddItem (strName)
Loop
 
ok....here is my code that accepts a form and loads a combobox on it.....hope this helps.

Public Sub LoadAircraftTypeMenu(frmIn As Form)

Set rs = New ADODB.Recordset
Set cmd = New ADODB.Command

With cmd
.ActiveConnection = gConn
.CommandText = "YOUR_SQL_VIEW"
.CommandType = adCmdUnknown
End With

Set rs = cmd.Execute

If Not rs.EOF Then
Do While Not rs.EOF
frmIn.cboAircraftType.AddItem rs.Fields("rec_desc")
rs.MoveNext
Loop
End If

Set cmd = Nothing
Set rs = Nothing

End Sub
 
Sorry but the name of the combobox on the form willn't be known. i was wondering if it can be found at run time. i want to be able to use this function for different forms that will have different name for the combobox

Thanks
 
So why can't you modify the code to find the name of the combo box and load the data then? A simple Switch or If statement would do that by looking at the control name.

Or just look to see if the control is a combo box and load it.


 
You can loop through the Controls collection:

Dim c as Control
For Each c in me.Controls
.
.
Next c

and use the Typeof Function

If TypeOf c is ComboBox Then myName = c.Name


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I kind of knew what it was but had forgotten

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top