Welcome to Dream.In.Code
Become a VB Expert!

Join 137,210 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,299 people online right now. Registration is fast and FREE... Join Now!




searching records

 
Reply to this topicStart new topic

searching records

emkaye
11 Jun, 2008 - 10:40 PM
Post #1

D.I.C Head
**

Joined: 12 Aug, 2007
Posts: 54


My Contributions
i just want to ask where should i put my codes. i have codes for searching records but the user will only have to enter first characters. then the program will return results of records which have the same first characters like the one entered by the user.

i was thinking if i should put my codes in the lost focus event of my textbox or should i put it in the click event of my command button.which is correct?
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Searching Records
11 Jun, 2008 - 10:58 PM
Post #2

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,914



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
If you want to implement something like autocomplete (i.e. search as you type) then you will need to add the code in the KeyPress Event.
Otherwise, use the Change event instead of LostFocus.

Lostfocus will trigger even if the user clicks a different control without changing the contents of the TextBox. The Change event gets triggered only if the text held in the textbox is changed, which I presume is exactly what you need.
smile.gif
User is offlineProfile CardPM
+Quote Post

emkaye
RE: Searching Records
11 Jun, 2008 - 11:12 PM
Post #3

D.I.C Head
**

Joined: 12 Aug, 2007
Posts: 54


My Contributions
i tried the following code:

CODE

Private Sub FindStr()
Dim strSQL As String
Dim resItem2 As ListItem
Dim recTempDialog As Recordset

lvRes.ListItems.Clear
strSQL = "select * from tblAgencyInfo where AGENCY_NAME LIKE '" & txtSearch & "*';"
Set recTempDialog = myConn.Execute(strSQL)

If recTempDialog.RecordCount Then
    recTempDialog.MoveFirst
    
    Do Until recTempDialog.EOF
        If Not IsNull(recTempDialog![AGENCY_NAME]) Then
            Set resItem2 = lvRes.ListItems.Add(, , recTempDialog.Fields("AGENCY_NAME"))
        Else
            lvRes.ListItems.Add ""
        End If
        
        recTempDialog.MoveNext
    Loop

Else
    MsgBox "There are No Agencies." & txtSearch.Text, vbInformation

End If

lvRes.Enabled = True


End Sub

Private Sub txtSearch_Change()
FindStr
End Sub


but an error occured:
either bof or eof is true, or the current record has been deleted.requested record requires a current record.

where

CODE

recTempDialog.MoveFirst


is highlighted.

what is wrong with my code.pls help.
User is offlineProfile CardPM
+Quote Post

mensahero
RE: Searching Records
12 Jun, 2008 - 02:36 AM
Post #4

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions


I remember implementing something like this..

CODE

recTempDialog.RecordCount


This doesn't make sense? it should be if recTempDialog.RecordCount <> 0

That way.. if no record found.. it will not execute the movefirst command..
User is offlineProfile CardPM
+Quote Post

tope10
RE: Searching Records
25 Jul, 2008 - 01:55 AM
Post #5

New D.I.C Head
*

Joined: 25 Jun, 2008
Posts: 22



Thanked: 2 times
My Contributions
vb
Private Sub FindStr()
Dim strSQL As String
Dim resItem2 As ListItem
Dim recTempDialog As Recordset

lvRes.ListItems.Clear
strSQL = "select * from tblAgencyInfo where AGENCY_NAME LIKE '" & txtSearch & "*';"
Set recTempDialog = myConn.Execute(strSQL)

If recTempDialog.RecordCount <> 0 Then
Do Until recTempDialog.EOF
If Not IsNull(recTempDialog![AGENCY_NAME]) Then
Set resItem2 = lvRes.ListItems.Add(, , recTempDialog.Fields("AGENCY_NAME"))
Else
lvRes.ListItems.Add ""
End If

recTempDialog.MoveNext
Loop

Else
MsgBox "There are No Agencies." & txtSearch.Text, vbInformation

End If

lvRes.Enabled = True


End Sub

Private Sub command1_click()
FindStr
End Sub



' base from your code i've learn that you want to type first all the character of an agency and if you click on something this will process the search criteria. So i change the txt_change to comman button. And in searching you have to check first if the value you entered in the text match to the record in the database, now in checking the record you have to use an if statement and here you use the recordcount property. I add something there which is to check if the recordcount is not equal to zero, meaning to say if the recordcount count is not = to 0 the where clause finds a record and the database. I ommited the movefirst function because you already pointed the search value using the clause.


You can also use Filter in searching record. this is how to use it..

vb
Private sub txtSearch_Change()
if txtsearch.text <> "" then
recTempDialog.filter ="AGENCY_NAME Like ' " & txtSearch & "*'"
else
recTempDialog.Filter ="AGENCY_NAME <> ' ' "
end if

End sub

User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Searching Records
25 Jul, 2008 - 09:33 AM
Post #6

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,914



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Hi tope10,
Use CODE Tags to enclose your code like this:
code.gif

I've done it for you this time.
Welcome to </dream.in.code>!
smile.gif
User is offlineProfile CardPM
+Quote Post

tope10
RE: Searching Records
25 Jul, 2008 - 07:47 PM
Post #7

New D.I.C Head
*

Joined: 25 Jun, 2008
Posts: 22



Thanked: 2 times
My Contributions
QUOTE(born2c0de @ 25 Jul, 2008 - 10:33 AM) *

Hi tope10,
Use CODE Tags to enclose your code like this:
code.gif

I've done it for you this time.
Welcome to </dream.in.code>!
smile.gif


QUOTE

Ok thanks for the info.


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 01:10PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month