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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Form

Status
Not open for further replies.

gasx

Technical User
Feb 28, 2003
22
US
I am working with vb6, to find record for one client I have to use arrow key to navigate through client form till I find the record for that client. So I use code below and is working fine, but I think there is easy way to search client form by insetting text box in client form and search record e.g. by phone number.

With rsClientNavigate
If .State = 1 Then
If .RecordCount > 0 Then
.MoveLast
Call FillclientInfo
End If
End If
End With

In ms access I use this code to find certain client by insetting this code on text box on after update event is working fine, but it wouldn’t work in vb6

Dim rs As DAO.Recordset
If Not IsNull(Me.clientphone) Then
'Save before move.
If Me.Dirty Then
Me.Dirty = False
End If
'Search in the clone set.
Set rs = Me.RecordsetClone
rs.FindFirst "[phone] = """ & Me.clientphone& """"
If rs.NoMatch Then
MsgBox "Not Found ," & vbCrLf & "Please enter a new phone number.", vbExclamation, "client form"

Else
'Display the found record in the form.
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End If


So I need help to fix this code to work with vb6

Thank you,
 
this is ADO which is newer
also instead of using Move command just return the results in a recordset. This is very fast as well.
Code:
    Dim Conn2 As ADODB.Connection
    Dim Rs1 As ADODB.Recordset

    Dim SQLCode As String
    
    Set Conn2 = New ADODB.Connection
    Set Rs1 = New ADODB.Recordset
    
    Conn2.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = c:\yourpath\yourdatabase.mdb"
    
    SQLCode = "SELECT * FROM YourTablename WHERE SomeField = something;"
    Rs1.Open SQLCode, Conn2, adOpenStatic, adLockOptimistic
'   Note: do normal rs1! or rs1. stuff from now on like
    me.yourcustomer = Rs1!customername
    me.Address =  Rs1!Address
    ...

'  close it this way
    Set rs1 = nothing
    Set Conn2 = nothing

you will need to Click on a reference in "Tools" "References" to "Microsoft Active Data Object 2.x"
see which is the latest one you have 2.1 - 2.5 or 2.6 or 2.7

DougP, MCP, A+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top