Click to See Complete Forum and Search --> : Search and display record.. Urgent! (Source code provided)


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

johnpc7
August 15th, 2001, 10:21 AM
MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation

else

frmCustomer.TxtFind = CustomerID

'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
End If
Unload me
rst.Close
cnn.Close
End Sub

johnpc7
August 15th, 2001, 10:21 AM
MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation

else

frmCustomer.TxtFind = CustomerID

'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
End If
Unload me
rst.Close
cnn.Close
End Sub

qiaojun
August 16th, 2001, 01:09 AM
According to your code, this will only display the customer Id. What about Customer Name, Customer Address, telephone, etc? I also want to show them all in frmCustomer too!

johnpc7
August 16th, 2001, 06:13 AM
Just put the required number of text boxes on the
form and code as below. If you would like to see
this method in an application go to:
http://johnpc.freeservers.com
and download the ADOTotals Program.


MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation

else
with frmCustomer
.TxtFind = CustomerID
.TxtCustomerName = Customer Name
.TxtCustomerAddress = Customer Address
.TxtCustomerTelephone = Customer Telephone
End With

'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
End If
Unload me
rst.Close
cnn.Close
End Sub

johnpc7
August 16th, 2001, 06:13 AM
Just put the required number of text boxes on the
form and code as below. If you would like to see
this method in an application go to:
http://johnpc.freeservers.com
and download the ADOTotals Program.


MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation

else
with frmCustomer
.TxtFind = CustomerID
.TxtCustomerName = Customer Name
.TxtCustomerAddress = Customer Address
.TxtCustomerTelephone = Customer Telephone
End With

'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
End If
Unload me
rst.Close
cnn.Close
End Sub