I know there has to be a better way to fill several Combo Boxes on a form. I'm using the SSTab Control and have 3 Combo Boxes that I need to fill from a database when the form loads. I tried using the click event, but I was going in circles.
This is what I have. It works, but as I said, there has to be a better way.
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Driver=SQL Server;uid=;pwd=;Server=Server;database=Test"
cn.Open
sql = "Select * from Hulls"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
rs.MoveFirst
Do Until rs.EOF = True
cboHulMake.AddItem rs.Fields("HulMake".Value
rs.MoveNext
Loop
rs.Close
sql = "Select * from SternDrives"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
rs.MoveFirst
Do Until rs.EOF = True
cboSdrMake.AddItem rs.Fields("SdrMake".Value
rs.MoveNext
Loop
rs.Close
sql = "Select * from Transmissions"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
rs.MoveFirst
Do Until rs.EOF = True
cboTrnMake.AddItem rs.Fields("TrnMake".Value
rs.MoveNext
Loop
rs.Close
End Sub
I am open for suggestions if someone has one, or Two. Rob
Just my $.02.
This is what I have. It works, but as I said, there has to be a better way.
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Driver=SQL Server;uid=;pwd=;Server=Server;database=Test"
cn.Open
sql = "Select * from Hulls"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
rs.MoveFirst
Do Until rs.EOF = True
cboHulMake.AddItem rs.Fields("HulMake".Value
rs.MoveNext
Loop
rs.Close
sql = "Select * from SternDrives"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
rs.MoveFirst
Do Until rs.EOF = True
cboSdrMake.AddItem rs.Fields("SdrMake".Value
rs.MoveNext
Loop
rs.Close
sql = "Select * from Transmissions"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
rs.MoveFirst
Do Until rs.EOF = True
cboTrnMake.AddItem rs.Fields("TrnMake".Value
rs.MoveNext
Loop
rs.Close
End Sub
I am open for suggestions if someone has one, or Two. Rob
Just my $.02.