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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox Problems

Status
Not open for further replies.

N1WVU

MIS
Jul 16, 2012
3
US
I am coding an database application where I need to open 4 different Comboboxes at the same time. When I run the program it deletes all of the records in my database for each table. That is that is erases the information in the fields and puts blanks lines in it. Here is the code that I am using to populate the combo boxes. I am performing this code in the form load sub.

Do Until adodc1.Recordset.EOF
Combo1.AddItem adodc1.Recordset!BuildingName
adodc1.Recordset.MoveNext
Loop

Do Until adodc2.Recordset.EOF
Combo2.AddItem adodc2.Recordset!DepartmentName
adodc2.Recordset.MoveNext
Loop

Do Until adoSubnet.Recordset.EOF
Combo3.AddItem adoSubnet.Recordset!SubnetAddress
adoSubnet.Recordset.MoveNext
Loop

Do Until adoIPAddress.Recordset.EOF
Combo4.AddItem adoIPAddress.Recordset!Field1IPAddress
adoIPAddress.Recordset.MoveNext
Loop

Thanks,
Mike StClair
 
Please tell us what the problem is and the results that you would like to obtain.

Beir bua agus beannacht!
 
You might try using a string variable as intermediary on each step, i.e.


Code:
Do Until adoIPAddress.Recordset.EOF
  wrkStr = adoIPAddress.Recordset!Field1IPAddress
  Combo4.AddItem wrkStr
  adoIPAddress.Recordset.MoveNext
Loop



 
N1WVU,
Have you tried using ADOD[blue]B[/blue] instead?
Something like:

Code:
Option Explicit[green]
'Projects - References... Add:
'Microsoft ActiveX Data Object X.X libarary[/green]
Dim Cn As ADODB.Connection

Private Sub Form_Load()

Dim str As String

str = "Driver={Microsoft ODBC for Oracle};" & _
            "SERVER=MyServer;; UID=MyID; PWD=passwd"

Set Cn = New ADODB.Connection
With Cn
    .ConnectionString = str
    .CursorLocation = adUseNone
    .Open
End With

str = "SELECT DISTINCT BuildingName " _
    & " From Buildings " _
    & " ORDER BY BuildingName"

Call FillCombo(Combo1, str)

str = "SELECT DISTINCT DepartmentName " _
    & " From Departments " _
    & " ORDER BY DepartmentName"
    
Call FillCombo(Combo2, str)

Cn.Close
Set Cn = Nothing

End Sub

Private Sub FillCombo(cbo As ComboBox, s As String)
Dim rst As ADODB.Recordset
Dim i As Integer

cbo.Clear

Set rst = New ADODB.Recordset
With rst
    .CursorType = adOpenForwardOnly
    .CursorLocation = adUseClient
    .LockType = adLockReadOnly
    .Open s, Cn

    If .RecordCount > 0 Then
        For i = 1 To .RecordCount
            cbo.AddItem .Fields(0).Value
            .MoveNext
        Next i
    End If
    .Close
End With
Set rst = Nothing

If cbo.ListCount > 0 Then
    cbo.ListIndex = 0
End If

End Sub

Select statements are just my guess :)

Have fun.

---- Andy
 
Actually I changed to a Datacombo box and every thing is working great.
Thanks,
Mike StClair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top