execute Access query/stored procedure with VB6?

execute Access query/stored procedure with VB6?

Post by dbasset.. » Thu, 14 Sep 2000 04:00:00



I need to be able to execute an Access query from my VB6 application.
Access
will not be installed on the end user machine but the query will
already be
in the .mdb file.

There is a reason why I need to do this as opposed to running an SQL
statement
in VB6 but I don't want to steer this post away from my initial
question so I'll
leave out the reason..

Anyway, it seems that this can be possible because if you use the ADO
control
to connect to an Access database, it shows the Query's as "Stored
Procedures", but
I just don't know how to go about actually executing a query..

The query will not return any data, it is strictly an "action" query
(such as Append,
Make table, etc..) so I don't need to show the results of the query...

Remember again that Access will not be installed so I don't want to use
any Access objects
in my code..

Dan

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

execute Access query/stored procedure with VB6?

Post by Alex Temeso » Thu, 14 Sep 2000 04:00:00


Hi Dan,

Here is the code you should use:

Private Db As ADODB.Connection

'Somewhere in procedure

Dim strCn As String
Dim lRecAffected As Long

     '-- set connection to Access db
     strCn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\DbName.mdb;"

     Set Db = New ADODB.Connection
     Db.Open strCn

     Db.Execute "QueryName", lRecAffected, adCmdStoredProc +
adExecuteNoRecords

     MsgBox lRecAffected & " Records Affected"

Hope this will help you out

With respect

Alex



> I need to be able to execute an Access query from my VB6 application.
> Access
> will not be installed on the end user machine but the query will
> already be
> in the .mdb file.

> There is a reason why I need to do this as opposed to running an SQL
> statement
> in VB6 but I don't want to steer this post away from my initial
> question so I'll
> leave out the reason..

> Anyway, it seems that this can be possible because if you use the ADO
> control
> to connect to an Access database, it shows the Query's as "Stored
> Procedures", but
> I just don't know how to go about actually executing a query..

> The query will not return any data, it is strictly an "action" query
> (such as Append,
> Make table, etc..) so I don't need to show the results of the query...

> Remember again that Access will not be installed so I don't want to
use
> any Access objects
> in my code..

> Dan

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

execute Access query/stored procedure with VB6?

Post by Dan Basset » Fri, 15 Sep 2000 11:17:53


Thanks, worked like a charm!!!!

Dan


> Hi Dan,

> Here is the code you should use:

> Private Db As ADODB.Connection

> 'Somewhere in procedure

> Dim strCn As String
> Dim lRecAffected As Long

>      '-- set connection to Access db
>      strCn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data
> Source=c:\DbName.mdb;"

>      Set Db = New ADODB.Connection
>      Db.Open strCn

>      Db.Execute "QueryName", lRecAffected, adCmdStoredProc +
> adExecuteNoRecords

>      MsgBox lRecAffected & " Records Affected"

> Hope this will help you out

> With respect

> Alex



> > I need to be able to execute an Access query from my VB6 application.
> > Access
> > will not be installed on the end user machine but the query will
> > already be
> > in the .mdb file.

> > There is a reason why I need to do this as opposed to running an SQL
> > statement
> > in VB6 but I don't want to steer this post away from my initial
> > question so I'll
> > leave out the reason..

> > Anyway, it seems that this can be possible because if you use the ADO
> > control
> > to connect to an Access database, it shows the Query's as "Stored
> > Procedures", but
> > I just don't know how to go about actually executing a query..

> > The query will not return any data, it is strictly an "action" query
> > (such as Append,
> > Make table, etc..) so I don't need to show the results of the query...

> > Remember again that Access will not be installed so I don't want to
> use
> > any Access objects
> > in my code..

> > Dan

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

> Sent via Deja.com http://www.deja.com/
> Before you buy.