Hi!
I have a problem with my combobox, it wont't display my recordset. The code works but i dosn't show the recordset in the combobox. What am I doing wrong ? suggestions?
The code:
Private Sub cmdSearch_Click()
Dim rstCustomer As ADODB.Recordset
Dim blnFound As Boolean
Dim fldItem As ADODB.Field
blnFound = False
If Me.txtName = "" Then Exit Sub
Set rstCusomer = New ADODB.Recordset
rstCustomer.Open "SELECT * FROM Customer WHERE Name = '" & _
txtName & "'", _
CurrentProject.Connection, _
adOpenStatic, adLockReadOnly, adCmdText
With rstCusomer
While Not .EOF
For Each fldItem In .Fields
If fldItem.Name = "Name" Then
If fldItem.Value = txtName Then
Me.comboBox1.AddItem .Fields("Id").Value
Me.comboBox1.AddItem .Fields("Name").Value
Me.comboBox1.AddItem .Fields("Address")
Me.comboBox1.AddItem .Fields("Zipcode")
Me.comboBox1.AddItem .Fields("Telefon")
Me.comboBox1.AddItem .Fields("Email")
Me.comboBox1.AddItem .Fields("Notes")
blnFound = True
End If
End If
Next
.MoveNext
Wend
End With
' If the item number was not found, ...
If blnFound = False Then
' ... let the user know, ...
MsgBox "Customer dosn't exist"
' ... and reset the form
cmdReset_Click
End If
rstCustomer.Close
Set rstCustomer = Nothing
End Sub
I have a problem with my combobox, it wont't display my recordset. The code works but i dosn't show the recordset in the combobox. What am I doing wrong ? suggestions?
The code:
Private Sub cmdSearch_Click()
Dim rstCustomer As ADODB.Recordset
Dim blnFound As Boolean
Dim fldItem As ADODB.Field
blnFound = False
If Me.txtName = "" Then Exit Sub
Set rstCusomer = New ADODB.Recordset
rstCustomer.Open "SELECT * FROM Customer WHERE Name = '" & _
txtName & "'", _
CurrentProject.Connection, _
adOpenStatic, adLockReadOnly, adCmdText
With rstCusomer
While Not .EOF
For Each fldItem In .Fields
If fldItem.Name = "Name" Then
If fldItem.Value = txtName Then
Me.comboBox1.AddItem .Fields("Id").Value
Me.comboBox1.AddItem .Fields("Name").Value
Me.comboBox1.AddItem .Fields("Address")
Me.comboBox1.AddItem .Fields("Zipcode")
Me.comboBox1.AddItem .Fields("Telefon")
Me.comboBox1.AddItem .Fields("Email")
Me.comboBox1.AddItem .Fields("Notes")
blnFound = True
End If
End If
Next
.MoveNext
Wend
End With
' If the item number was not found, ...
If blnFound = False Then
' ... let the user know, ...
MsgBox "Customer dosn't exist"
' ... and reset the form
cmdReset_Click
End If
rstCustomer.Close
Set rstCustomer = Nothing
End Sub