Link to home
Start Free TrialLog in
Avatar of Rodger49
Rodger49

asked on

VB 6 and Access

I have a program in vb 6 program that is connected to access 2007. In the database I have over 3000  entry's. I want to search for a name or account number to bring up all the information on that person. How do I do it. I tried search and find but no help.
Avatar of gplana
gplana
Flag of Spain image

You should use a recordset. Here is an example:

Dim conn As New ADODB.Connection 'la conexion a la base de datos Access
Dim rs As ADODB.Recordset 'iterador que contiene los datos de una consulta
Dim path As String 'archivo de la base de datos Access

path = "c:\datos.mdb"

'Realizamos la conexión
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";Persist Security Info=False"
conn.Open

'Realizamos la consulta
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM corredores", conexion, adOpenKeyset, adLockOptimistic

'Modificamos los controles del formulario
Set DataGrid1.DataSource = rs
Text1.Text = rs.RecordCount

Open in new window

On line 13 there is the SELECT statement that will be run by access. If you want to filter by name use something like:

rs.Open "SELECT * FROM you_table WHERE name='" . the_name . "'", conn, adOpenKeyset, adLockOptimistic

Open in new window


If you want to search by account number:

rs.Open "SELECT * FROM you_table WHERE account_number=" . the_account_number, conn, adOpenKeyset, adLockOptimistic

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rodger49
Rodger49

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rodger49
Rodger49

ASKER

Still can't get the program to work. when I click the command button I get the error message 3001