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!

Filling combo box 1

Status
Not open for further replies.

aos

MIS
Feb 28, 2002
20
US
As it stands, i have code that pulls in data to fill the combo box. The same guest can appear several times (because the guest can be booked for more than one night). How do i get the combo box to pull in the names that are unique to one telephone number?
Filling combo box:
Dim adoconnection As ADODB.Connection
Set adoconnection = New ADODB.Connection

adoconnection.Open ("Provider=Microsoft.jet.oledb.4.0;" & "Data Source = h:\IS4401Project\DB.mdb")
cboName.Clear
Set rs = New ADODB.Recordset

rs.Open "select Guest From ListDates", adoconnection
While Not rs.EOF

cboName.AddItem rs("Guest")

rs.MoveNext
Wend



On the click of the combo box, data on that guest appears:
Private Sub cboName_Click()
Dim adoconnection As ADODB.Connection
Set adoconnection = New ADODB.Connection

adoconnection.Open ("Provider=Microsoft.jet.oledb.4.0;" & "Data Source = H:\IS4401Project\DB.mdb")

Set rs = New ADODB.Recordset
Dim guest As String
guest = cboName.Text
rs.Open "Select * from ListDates where Guest = '" & guest & "'", adoconnection, adOpenDynamic, adLockOptimistic

If rs.BOF Then 'if bof and eof true, no records remain
MsgBox "The recordset is empty.", vbInformation, "No records"
Else
rs.MoveFirst
If Not rs.EOF Then

txtTel.Text = rs!TelephoneNumber
If IsNull(rs!creditcardno) Then
txtCCNo.Text = ""
Else
txtCCNo.Text = rs!creditcardno
End If
txtDateofStay = rs!Date
If IsNull(rs!CreditCardExpiry) Then
txtExpiry = ""
Else
txtExpiry = rs!CreditCardExpiry
End If
txtRm = rs!RoomNo

rs.MoveNext
End If
End If

End Sub
 
Hi,
You could try this sql statement to fill you combobox



rs.open "SELECT Guest FROM ListDates GROUP BY Guest ORDER BY Guest",adoconnection
While Not rs.EOF
cboName.AddItem rs("Guest")
rs.MoveNext
Wend
 
Hi,
You could try this sql statement to fill you combobox



rs.open "SELECT Guest FROM ListDates GROUP BY Guest ORDER BY Guest",adoconnection
While Not rs.EOF
cboName.AddItem rs("Guest")
rs.MoveNext
Wend

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top