Searching Access via VB

jesse-jordan
04-13-2004, 11:56 AM
I want to search my access database in vb. I need it to search and then put the results into a list box with two columns. I'm not allowed to use sql though, I am really stuck can anyone help! It is probably really simple.

Thanks

Jesse

Heres the code I use at the minute to search:

Private Sub cmdSearch_Click()
Dim strSearchFor As String, FoundFlag As Boolean
strSearchFor = InputBox("Enter Students Name:")

Data1.Recordset.MoveFirst
FoundFlag = False

While (Not FoundFlag) And (Not Data1.Recordset.EOF)
If Data1.Recordset.Fields("StudentName").Value = strSearchFor Then
FoundFlag = True
Else
Data1.Recordset.MoveNext
End If
Wend
If FoundFlag Then
MsgBox "Found It!"
Else
MsgBox "Sorry"
End If
End Sub

LaVolpe
04-13-2004, 12:24 PM
What is the problem? Does your search routine ever set FoundFlag to True?
P.S. You're using SQL anyway. The Data control uses SQL to talk to your database.

jesse-jordan
04-13-2004, 12:46 PM
What is the problem? Does your search routine ever set FoundFlag to True?
P.S. You're using SQL anyway. The Data control uses SQL to talk to your database.

The problem is that i don't now how to do the search. I want to do it a different way to the way I currently do it. so results go into a listbox and have two columns.

davieboy_xr
04-13-2004, 01:38 PM
have you had a look at flyguys faqs on ado and databases... its at the top of the forum.

loquin
04-13-2004, 01:58 PM
So, is the instructor forcing you to use ado data controls (or just data controls) to access the table, then you apply a filter to the control? This is really the only approach where you wouldn't use SQL directly (only indirectly, via the data control)

Afte tthe filter is applied, just loop through the data control, copying the data from it into a listbox

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum