Re: Run query using VB6 and DAO

From: Wart (nospamWart_at_epix.net)
Date: 11/26/04


Date: Fri, 26 Nov 2004 18:39:51 -0500

Stefanie,
I would suggest ADO instead of DAO.
Depending on your database, make a connection to it using the ADO connection
object.
Use the Connection to open a RecordSet.
Iterate through the RecordSet for your results.
The easiest way to use the parameter from your TextBox would be inline SQL
but there will be a cry from others about the security hole this creates and
so you should look into parameterized queries when you have more comfort.
So somewhere in your app you could do something like as follows:
Dim lsSql as string
lsSql = "Select * from MyTable where Field1 = '" & MyTextBox.Text & "'"
MyRs.Open lsSql, MyConnection, adOpenStatic, adLockOptimistic
Do While Not MyRS.EOF
    TextField1 = MyRS.Fields(0)
    TextField2 = MyRS.Fields(1)
    'Write to the file
    MyRS.MoveNext
Loop
HTH,
CF

"Stefanie" <Stefanie@zsmail.net> wrote in message
news:%232CDgq%230EHA.1192@tk2msftngp13.phx.gbl...
> Hi,
>
> I'am new to database programming so please be patient.
>
> I created a database with one table (two fields) and one query (both
> fields from the table and sorted)
> Now i'd like to run this query from my VB6 application with some input.
> So i have a textbox on my form for a parameter in my query.
> How can i receive the values from field 1 and field 2 running my query.
> (I have to write these values to a file)
>
> (BTW i'am using DAO but i don't know if this is the best for a table with
> about 2,000,000 records.)
>
> Q1: How to run the query with a parameter from my textbox
> Q2: How to receive te results (i know how to write them to a file)
>
> Stefanie
>
>
>



Relevant Pages

  • Re: JET DAO access to Access 97 from VB4 in XP SP2
    ... DAO 3.5x should be sufficient for Access 97. ... Doug Steele, Microsoft Access MVP ... >> Dim db As Database ... >> connection to get reasonable connection speeds to the database. ...
    (microsoft.public.vb.database.dao)
  • Re: "File Already Open" error in Data Report
    ... > When the data report invokes the data environment, ... Do I need to drop the DAO connection before I ... You didn't mention the database type, but since you were using DAO I assume ...
    (microsoft.public.vb.general.discussion)
  • Re: converting exclusive DAO connection object to an ADO.Net connection object
    ... I have a vb application that uses Jet.Oledb with DAO 3.51 over an MS ... Access database. ... .net portion of the application uses ado.net oledb connections. ... application opens the database in exclusive mode, the same connection ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Need Advice - Access XP and ADO
    ... I changed the ADO connection to point to a database in another directory. ... My ADO Connection component is built to point to the valid and active ...
    (borland.public.delphi.database.ado)
  • Re: Use ADO in Access 2000?
    ... There are some things you can _only_ do with DAO. ... CodeProject returns the connection to wherever the code ... Is this why I can't find a single example> of connecting to the current Access database using ADO? ...
    (microsoft.public.access.modulesdaovba)