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
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