qiaojun
August 15th, 2001, 01:27 AM
I have a customer form and a search form. if user enters customer id and a record is found, how am i going to display them on the customer form and re-assign the record pointer? Below code belongs to the command "Search" on Search form.
private Sub cmdSearch_Click()
Dim cnn as new ADODB.Connection
Dim rst as new ADODB.Recordset
Dim mark as Variant
Dim count as Integer
count = 0
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ims.mdb;Persist Security Info=false"
rst.Open "SELECT CustomerId FROM Customers", cnn, adOpenStatic, adLockReadOnly, adCmdText
' The default parameters are sufficient to search forward
' through a Recordset.
rst.Find "CustomerId LIKE '" & txtCustomerID.Text & "'"
' Skip the current record to avoid finding the same row repeatedly.
' The bookmark is redundant because Find searches from the current
' position.
Do While rst.EOF <> true 'Continue if last find succeeded.
count = count + 1 'Count the last title found.
mark = rst.Bookmark 'Note current position.
rst.Find "CustomerId LIKE '" & txtCustomerID.Text & "'", 1, adSearchForward, mark
Loop
If count = 0 then
MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation
else
'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
End If
Unload me
rst.Close
cnn.Close
End Sub
private Sub cmdSearch_Click()
Dim cnn as new ADODB.Connection
Dim rst as new ADODB.Recordset
Dim mark as Variant
Dim count as Integer
count = 0
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ims.mdb;Persist Security Info=false"
rst.Open "SELECT CustomerId FROM Customers", cnn, adOpenStatic, adLockReadOnly, adCmdText
' The default parameters are sufficient to search forward
' through a Recordset.
rst.Find "CustomerId LIKE '" & txtCustomerID.Text & "'"
' Skip the current record to avoid finding the same row repeatedly.
' The bookmark is redundant because Find searches from the current
' position.
Do While rst.EOF <> true 'Continue if last find succeeded.
count = count + 1 'Count the last title found.
mark = rst.Bookmark 'Note current position.
rst.Find "CustomerId LIKE '" & txtCustomerID.Text & "'", 1, adSearchForward, mark
Loop
If count = 0 then
MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation
else
'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
End If
Unload me
rst.Close
cnn.Close
End Sub