docmd clear me please

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

docmd clear me please

Post by sal21 »

I few day ago Hans suggest me to export a fields with delimited ";" to use a docmd ...
But i have this prob:
I need to export not all fields but for example field1, field5, ecc... from table1 where field5= ecc...
Is possible to integrate into the command line a string query just created from other use inexisting part of code in my vb6 project?

User avatar
HansV
Administrator
Posts: 78575
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: docmd clear me please

Post by HansV »

DoCmd.TransferText only works with tables and (stored) queries, not with SQL strings.

One option would be to create a stored query with the SQL that you need, and to export that using DoCmd.TransferText.

Another option would be to open a recordset and to write it to a text file line by line.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

Re: docmd clear me please

Post by sal21 »

HansV wrote:DoCmd.TransferText only works with tables and (stored) queries, not with SQL strings.

One option would be to create a stored query with the SQL that you need, and to export that using DoCmd.TransferText.

Another option would be to open a recordset and to write it to a text file line by line.
"create a stored query..." into the access data base?

User avatar
HansV
Administrator
Posts: 78575
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: docmd clear me please

Post by HansV »

Yes.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

Re: docmd clear me please

Post by sal21 »

HansV wrote:Yes.
Ok, and how to integrate into the docmd command line the query nmed Query1?

User avatar
HansV
Administrator
Posts: 78575
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: docmd clear me please

Post by HansV »

For example:

DoCmd.TransferText acExportDelim, , "Query1", "C:\Documents\MyFile.txt", True
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

Re: docmd clear me please

Post by sal21 »

HansV wrote:For example:

DoCmd.TransferText acExportDelim, , "Query1", "C:\Documents\MyFile.txt", True
OK perfect test and it work !!!!!!!!!!!!!!!!!

But only a tips.

Admit i have a myquery in access database similar:
select * from my table where filed1="Data"

i know is possible to call via RS.Open "myquery", CONN..ecc but admit Data is a variable is possible to pass this param from my vb6 codfe into query stored in access database?

Peraphs i'm stupid but...

User avatar
HansV
Administrator
Posts: 78575
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: docmd clear me please

Post by HansV »

You need the ADOX library for that: set a reference to the "Microsoft ADO Ext. 2.n for DDL and Security" library (the version number depends on your installation).

See Creating and Modifying Stored Queries in Microsoft Access Databases with ADOX
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

Re: docmd clear me please

Post by sal21 »

HansV wrote:You need the ADOX library for that: set a reference to the "Microsoft ADO Ext. 2.n for DDL and Security" library (the version number depends on your installation).

See Creating and Modifying Stored Queries in Microsoft Access Databases with ADOX
This tips ?:
Modifying a Query

Code: Select all

Sub ModifyQuery(strDBPath As String, _
                strQryName As String, _
                strSQL As String)
   Dim catDB As ADOX.Catalog
   Dim cmd   As ADODB.Command
   
   Set catDB = New ADOX.Catalog
   ' Open the Catalog object.
   catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & strDBPath
   
   Set cmd = New ADODB.Command
   ' Get the query from the Procedures collection.
   Set cmd = catDB.Procedures(strQryName).Command
   
   ' Update the query's SQL statement.
   cmd.CommandText = strSQL
   
   'Save the updated query.
   Set catDB.Procedures(strQryName).Command = cmd
   
   Set catDB = Nothing
End Sub

User avatar
HansV
Administrator
Posts: 78575
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: docmd clear me please

Post by HansV »

Yes, indeed.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

Re: docmd clear me please

Post by sal21 »

HansV wrote:Yes, indeed.
ops!
Errore 3265(?!)
Last edited by sal21 on 29 Nov 2010, 01:07, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78575
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: docmd clear me please

Post by HansV »

For a query, use Views instead of Procedures.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

Re: docmd clear me please

Post by sal21 »

HansV wrote:For a query, use Views instead of Procedures.
AS USUAL.... :clapping: :fanfare: :clapping: :clapping: :clapping: :clapping: :thankyou: