|
-
Mar 20th, 2001, 08:50 PM
#1
Thread Starter
PowerPoster
Ok again sorry for putting it here!!
Now this piece of code searches a database and returns a result in msgboxes!
Problem is it stops as soon as it has found 1 result. If there are 2 or more results it won't display them!
Can someone add to this and tell me how i can get it to continue searching for other results then display them all at the end?
cheers
-
Mar 20th, 2001, 08:52 PM
#2
Add to what? Where's your code?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 20th, 2001, 08:56 PM
#3
PowerPoster
Just taking a stab, since there is no code to go along with it, you may be using the find function, so just use a loop eof = true. After it finds whatever your searching for, dump it in an array or whatever you want, and start the search from where it left off. You may have to use a bookmark.
-
Mar 20th, 2001, 09:05 PM
#4
Thread Starter
PowerPoster
Dont mind me off in my own little dream world!!
Here we go!! Sorry
Private Sub Command2_Click()
Dim res1 As String
Dim res2 As String
Dim res3 As String
Set rs = db.OpenRecordset("SELECT * FROM mail")
NameQuery = InputBox("Enter A Date To Search For", "Date Query")
rs.MoveFirst
Do Until rs.EOF
If rs.Fields("Date") Like "*" & LCase(NameQuery) & "*" Then
res1 = rs.Fields("Date")
res2 = rs.Fields("Addressee")
res3 = rs.Fields("Description")
MsgBox res1
MsgBox res2
MsgBox res3
Exit Sub
Else
rs.MoveNext
End If
Loop
End Sub
-
Mar 20th, 2001, 10:07 PM
#5
Fanatic Member
Changes to make are bolded.
Private Sub Command2_Click()
Dim res1 As String
Dim res2 As String
Dim res3 As String
Set rs = db.OpenRecordset("SELECT * FROM mail")
NameQuery = InputBox("Enter A Date To Search For", "Date Query")
rs.MoveFirst
Do Until rs.EOF
If rs.Fields("Date") Like "*" & LCase(NameQuery) & "*" Then
res1 = rs.Fields("Date")
res2 = rs.Fields("Addressee")
res3 = rs.Fields("Description")
MsgBox res1
MsgBox res2
MsgBox res3
Exit Sub ' remove this line
end if
rs.MoveNext
End If
Loop
End Sub
-
Mar 20th, 2001, 10:16 PM
#6
Thread Starter
PowerPoster
ta ppl
Cheers
Actually only needed to remove "Exit Sub" and add another rs.movenext!
Cheers once again
-
Mar 21st, 2001, 12:07 AM
#7
Fanatic Member
Why an extra rs.movenext? By putting the rs.movenext after the end if, you make a second rs.movenext statement redundant.
-
Mar 21st, 2001, 12:18 AM
#8
Thread Starter
PowerPoster
-
Mar 21st, 2001, 12:34 AM
#9
Fanatic Member
-
Mar 21st, 2001, 12:53 AM
#10
Fanatic Member
Originally posted by Beacon
Dim res1 As String
Dim res2 As String
Dim res3 As String
this can be shortened to Dim res1,res2,res3 as string
Just a helpful hint
Regards
E.P.
-
Mar 21st, 2001, 12:55 AM
#11
PowerPoster
Extreme Pimpness, your code declared only the last variable as a string, while the others are declared as variants...just a helpful hint..
-
Mar 21st, 2001, 12:57 AM
#12
Fanatic Member
E.P, I don't think so.
Dim res1,res2,res3 as string: will declare res1 and res2 as variants and res3 as a string.
-
Mar 21st, 2001, 12:57 AM
#13
Fanatic Member
i am sorry it is early or late i can't tell the differance anymore but the point was you can ommit the other two dim statements
-
Mar 21st, 2001, 12:58 AM
#14
PowerPoster
Hey james, 2 great minds think alike eh.....
-
Mar 21st, 2001, 01:05 AM
#15
Fanatic Member
Yep, I hate variants, they chew up my resources hungry little bastards.
-
Mar 21st, 2001, 01:15 AM
#16
Hyperactive Member
Originally posted by Beacon
Dont mind me off in my own little dream world!!
Here we go!! Sorry
Code:
Private Sub Command2_Click()
Dim res1 As String
<snipped>
Do Until rs.EOF
If rs.Fields("Date") Like "*" & LCase(NameQuery) & "*" Then
res1 = rs.Fields("Date")
<snipped>
MsgBox res1
<snipped>
Exit Sub 'Remove
Else 'Remove
rs.MoveNext 'Remove
End If
rs.MoveNext 'Add this line
Loop
End Sub
ExtremePimpness, so early you are into .NET already 
Anyway, it just help reduce some time for conversion when porting the code over to .NET in the future.....hehe. Variant? Let it be now, as it will no longer be....
Harddisk
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|