VBA Make table Query to a different drive? 
Author Message
 VBA Make table Query to a different drive?

A helpfull soul once posted a routine to run a make table query
programatically, it went something like this:

Dim db as DAO.Database
Set db = CurrentDb
db.Execute "Select MyTable.* INTO NewTable From MyTable", dbFailOnError

And it works great.

My problem is that I want the table to be made in a different database
on a different drive. Any Takers?

    Next Question. Why can't I cut and paste a select query SQL
statement into a procedure. Every time I try I get no end of errors.
Could someone post a simple procedure that programatically runs a select
query? I already learned that you cannot "Execute" a select query.

Any Help will be greatly appreciated.
--

Thank You

Bill Rodgers



Tue, 29 Oct 2002 03:00:00 GMT  
 VBA Make table Query to a different drive?
I'm not too sure about your first question (creating the table in a
different mdb).  As for programatically running the select query, you are
correct in saying you can't execute a SELECT query.  But you can create a
recordset from a SELECT query.  For example, if you wanted to Debug.Print
the contents of Field1 for every record in Table1, you could do the
following:

Sub PrintOut
     Dim db As Database
     Dim rs As Recordset
     Set db = CurrentDB
     Set rs = db.openrecordset("SELECT Table1.Field1 FROM Table1;")
     rs.MoveFirst
     Do While Not rs.EOF
          Debug.Print rs!Field1
          rs.MoveNext
     Loop
End

Or, if you have a query called Query1 (defined as the SQL used above), and
you want to do the same thing, you can do the following:

Sub PrintOut2
     Dim db As Database
     Dim qd As QueryDef
     Dim rs As Recordset
     Set db = CurrentDB
     Set qd = db.QueryDefs("Query1")
     Set rs = qd.OpenRecordset
     rs.MoveFirst
     ....etc.
End

As for cutting-and-pasting the SQL, you can kinda do that.  What I've found
usefull is to define a string variable, and store the results of the paste
into the string variable, and then use the string variable in place of the
"Query1" or the "SELECT" as used above.  For example, if you cut and paste
the SQL from a query into a module, you'll get something like:
     SELECT *
     FROM Table1
     WHERE(((Field1)="A"));

You'll want to change it so it looks like:
     Dim sSQL As String
     sSQL = "SELECT * FROM Table1 WHERE(((Field1)=""A""));"

Note:  The double-quotes in the string (around the A) will convert to a
single-quote within the variable.  Then you could do things like:
     Set rs = db.OpenRecordset(sSQL)

Does that help?

Michael Kucan


Quote:
>A helpfull soul once posted a routine to run a make table query
>programatically, it went something like this:

>Dim db as DAO.Database
>Set db = CurrentDb
>db.Execute "Select MyTable.* INTO NewTable From MyTable", dbFailOnError

>And it works great.

>My problem is that I want the table to be made in a different database
>on a different drive. Any Takers?

>    Next Question. Why can't I cut and paste a select query SQL
>statement into a procedure. Every time I try I get no end of errors.
>Could someone post a simple procedure that programatically runs a select
>query? I already learned that you cannot "Execute" a select query.

>Any Help will be greatly appreciated.
>--

>Thank You

>Bill Rodgers



Tue, 29 Oct 2002 03:00:00 GMT  
 VBA Make table Query to a different drive?
SELECT MyTable.* INTO [full path to other db\otherdb.mdb].NewTable
FROM MyTable

Joan


Quote:
>A helpfull soul once posted a routine to run a make table query
>programatically, it went something like this:

>Dim db as DAO.Database
>Set db = CurrentDb
>db.Execute "Select MyTable.* INTO NewTable From MyTable", dbFailOnError

>And it works great.

>My problem is that I want the table to be made in a different database
>on a different drive. Any Takers?

>    Next Question. Why can't I cut and paste a select query SQL
>statement into a procedure. Every time I try I get no end of errors.
>Could someone post a simple procedure that programatically runs a select
>query? I already learned that you cannot "Execute" a select query.

>Any Help will be greatly appreciated.
>--

>Thank You

>Bill Rodgers



Tue, 29 Oct 2002 03:00:00 GMT  
 VBA Make table Query to a different drive?
 To fidle with data in an external db instead of this:
Set dbTbl_ImportPaid = CurrentDb

try this.
 Set dbTbl_ImportPaid = OpenDatabase("VIDP20041999-343467_Paid.mdb")


Quote:
> A helpfull soul once posted a routine to run a make table query
> programatically, it went something like this:

> Dim db as DAO.Database
> Set db = CurrentDb
> db.Execute "Select MyTable.* INTO NewTable From MyTable", dbFailOnError

> And it works great.

> My problem is that I want the table to be made in a different database
> on a different drive. Any Takers?

>     Next Question. Why can't I cut and paste a select query SQL
> statement into a procedure. Every time I try I get no end of errors.
> Could someone post a simple procedure that programatically runs a select
> query? I already learned that you cannot "Execute" a select query.

> Any Help will be greatly appreciated.
> --

> Thank You

> Bill Rodgers



Sat, 09 Nov 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Sort query results according to criteria from different table

2. Query Builder: Join table from different MDB?

3. Query Builder: Join table from different MDB?

4. Query data from tables in two different databases

5. Querying two recordset objects or Joining tables from different datastores

6. Update Query between tables in 2 different ADO.connections

7. Help on making a table Boolean field into a Check Box using VBA

8. VBA : making table with a form

9. verifying the existance of a table,query or form through vba

10. Launching a different database from a different db w/ vba

11. create a table from a crosstab parameter query in VBA

12. Acc2000: Executing a Create Table Query in VBA

 

 
Powered by phpBB® Forum Software