Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2006, 11:29 AM
Registered User
 
Join Date: Mar 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do you open a specific record from a search?

The search part of my code works. You type in a phone number and it searches through all 4 tables and finds a match. When it finds the match it brings up the right form based on the table it was found in, but it brings up the very first record within that table.
How do I get it to open up the specific record that I was searching for in the right form?
Here is my code:

Private Sub cmdfind_Click()
    txtsearch.Text = Format(txtsearch.Text, "(###) ###-####")
    Dim dbsClients As Database
    Dim rsClients As Recordset
    Dim rsSenior As Recordset
    Dim rsMFY As Recordset
    Dim rsNewborn As Recordset
    Dim strPhone As String
    Dim intReply As Integer
    Dim intCcount, intScount, intMcount, intNcount As Integer
    strPhone = "[Phone 1] = " & "'" & txtsearch.Text & "'"
    Set dbsClients = OpenDatabase("ClientInfoList97.mdb")
    Set rsClients = dbsClients.OpenRecordset("Client Info", dbOpenDynaset)
    Set rsSenior = dbsClients.OpenRecordset("Seniors", dbOpenDynaset)
    Set rsMFY = dbsClients.OpenRecordset("My First Year", dbOpenDynaset)
    Set rsNewborn = dbsClients.OpenRecordset("Newborn Memories", dbOpenDynaset)
    intCcount = rsClients.RecordCount
    intScount = rsSenior.RecordCount
    intMcount = rsMFY.RecordCount
    intNcount = rsNewborn.RecordCount

    rsClients.FindFirst strPhone
    If rsClients.NoMatch = False Then

       rsClients.OpenRecordset
       frmclient.Show

       Unload frmsearch

    End If

    If rsClients.NoMatch = True Then
        rsSenior.FindFirst strPhone
        If rsSenior.NoMatch = False Then

        datseniors.Recordset.OpenRecordset
        frmsenior.Show
        Unload frmsearch
        If rsSenior.NoMatch = True Then
            rsMFY.FindFirst strPhone
            If rsMFY.NoMatch = False Then

            datmfy.Recordset.OpenRecordset
            frmmfy.Show
            Unload frmsearch
            If rsMFY.NoMatch = True Then

                rsNewborn.FindFirst strPhone
                If rsNewborn.NoMatch = False Then

                datnewborn.Recordset.OpenRecordset
                frmnewborn.Show
                Unload frmsearch
                If rsNewborn.NoMatch = True Then
                    intReply = MsgBox("Sorry there was no record with that Phone number.", vbOKOnly, "Client Not Found")

                     If intReply = vbOK Then Unload frmsearch
                     frmsearch.Show

                    End If
                End If
            End If
        End If
        End If
        End If
        End If
End Sub

~Sandy
 
Old March 31st, 2006, 12:57 AM
Registered User
 
Join Date: Mar 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to brookhou
Default

Try looping through your records:

rsClients.RecordSet.MoveFirst
If rsClients.NoMatch = False Then
 Do Until txtsearch.Text = strPhone
   rsClients.RecordSet.MoveNext
 Loop
 rsClients.OpenRecordset
 frmclient.Show
 Unload frmsearch
End If





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search specific data from specific columns yogeshyl SQL Language 1 January 16th, 2008 11:12 AM
choose specific record ar555 Dreamweaver (all versions) 12 January 12th, 2007 01:04 PM
Open a PDF to a Specific Bookmark SerranoG Access VBA 2 March 7th, 2006 04:17 PM
Link to a specific record rexecampbell Classic ASP Basics 2 April 7th, 2004 01:40 PM
How to search and display in textbox a specific .. arshad mahmood VB Databases Basics 1 July 11th, 2003 08:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.