I understand it's easy to list all saved queries of a given Access
database via Msysobjects system table. However, I have not seen any
posting over this NG or other similar ones that also include SQL
statement(conte nt) of these queries, though I've noticed some VB code
for that. Is that because it's simply impossible to get a query
content (not query resultset) from a SQL stmt?
Thanks in advance. 35 2543
huh? You want the SQL query typed out and the resulting recordset it
describes?
Where to? You can loop through the querydefs collection and print the
querydef's SQL
dim qdf as dao.querydef 'redundant, cuz ado doesn't have a querydef
object
for each qdf in dbengine(0)(0). querydefs
debug.print qdf.name
debug.print qdf.SQL
debug.print 'blank line
next qdf
Very good and I appreciate it. Now, two things here.
(A) The given Access database has tons of queries, over 200, so, the
debugging runs out of its default capacity, it hasn't finished even B
yet;
(B) So, is it feasible to interface with File System, that is, write
each query to a single file (query name as file name, query content as
file content and so on and so forth)?
Good job, again thanks.
Take a look at what Arvin Meyer has at http://www.datastrat.com/Code/DocDatabase.txt
That will dump not only the queries but the forms, reports, modules and
macros, each into its own file.
--
Doug Steele, Microsoft Access MVP http://I.Am/DougSteele
(no e-mails, please!)
"NickName" <da****@rock.co m> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com... Very good and I appreciate it. Now, two things here. (A) The given Access database has tons of queries, over 200, so, the debugging runs out of its default capacity, it hasn't finished even B yet; (B) So, is it feasible to interface with File System, that is, write each query to a single file (query name as file name, query content as file content and so on and so forth)?
Good job, again thanks.
Douglas,
Thank you very much for the pointer. It seems great for the idea of
what I intend to do with this db, and we're getting close. With a
little tweak I can get what I need, however,
(A) the undocumented command/function of Application.Sav eAsText can't
seem to handle other object other than dbs.QueryDefs(i ).Name,
as the following
Application.Sav eAsText acQuery, dbs.QueryDefs(i ).{otherThanNam eObject--
you get the idea}, "C:\aFolder\its Sub\" & dbs.QueryDefs(i ).Name &
".txt"
what alternative may I apply?
(B) What if I want to save all the queries into a big AllQueries file?
Again I truly appreciate it.
SaveAsText needs the name of the query (or whatever) as its 2nd parameter.
What would you want to put there instead? (Have you looked at what gets
saved?)
No, I don't believe it would be possible using SaveAsText to put everything
into a single file. You could write each one to a file, append that file to
the "master file", then delete the first file you created. Messy, and
probably not much better than looping writing the text out yourself.
--
Doug Steele, Microsoft Access MVP http://I.Am/DougSteele
(no e-mails, please!)
"NickName" <da****@rock.co m> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com... Douglas,
Thank you very much for the pointer. It seems great for the idea of what I intend to do with this db, and we're getting close. With a little tweak I can get what I need, however, (A) the undocumented command/function of Application.Sav eAsText can't seem to handle other object other than dbs.QueryDefs(i ).Name, as the following Application.Sav eAsText acQuery, dbs.QueryDefs(i ).{otherThanNam eObject-- you get the idea}, "C:\aFolder\its Sub\" & dbs.QueryDefs(i ).Name & ".txt" what alternative may I apply? (B) What if I want to save all the queries into a big AllQueries file?
Again I truly appreciate it.
OK, what I meant by
//
Application.Sav eAsText acQuery,
dbs.QueryDefs(i ).{otherThanNam *eObject--
you get the idea}, "C:\aFolder\its Sub\" & dbs.QueryDefs(i ).Name &
".txt"
//
is
Application.Sav eAsText acQuery, dbs.QueryDefs(i ).SQL,
"C:\aFolder\its Sub\" & dbs.QueryDefs(i ).Name &
".txt"
so as to get a query's content (sql statement), however,
Application.Sav eAsText method won't do the job.
Is there another way to output dbs.QueryDefs(i ).SQL to file?
Thanks.
How about something like this:
Public Sub WriteSQLsToFile (ByVal strFile As String)
On Error Resume Next
Dim qdf As DAO.QueryDef
Dim intFileNumber As Integer
intFileNumber = FreeFile ' Get unused file number.
Kill strFile
Open strFile For Output As #intFileNumber ' Create file name.
For Each qdf In DBEngine(0)(0). QueryDefs
If Left$(qdf.Name, 1) <> "~" Then
Print #intFileNumber, qdf.Name
Print #intFileNumber, "-----------"
Print #intFileNumber, qdf.SQL
Print #intFileNumber, ""
Print #intFileNumber, ""
End If
Next qdf
Close #intFileNumber ' Close file.
MsgBox "All queries written to " & vbCrLf & strFile
End Sub
Oh, this is wrong then... You'd have to open your new file INSIDE the
loop, and close it there too. pass the queryname or something and
output. Maybe do something fun like a routine to strip out illegal
characters or whatever.... but I have to leave SOME of the fun for
you... I mean, otherwise, what do you learn from all of my work?
Nothing.
"NickName" <da****@rock.co m> wrote in
news:11******** **************@ g47g2000cwa.goo glegroups.com: OK, what I meant by // Application.Sav eAsText acQuery, dbs.QueryDefs(i ).{otherThanNam *eObject-- you get the idea}, "C:\aFolder\its Sub\" & dbs.QueryDefs(i ).Name & ".txt" // is Application.Sav eAsText acQuery, dbs.QueryDefs(i ).SQL, "C:\aFolder\its Sub\" & dbs.QueryDefs(i ).Name & ".txt" so as to get a query's content (sql statement), however, Application.Sav eAsText method won't do the job. Is there another way to output dbs.QueryDefs(i ).SQL to file?
I think you have a fundamental misunderstand of what SaveAsText
does. It's a command that saves all the properties of Access objects
to text files. If you do:
application.sav eastext acquery, [queryname], [filename]
You'll get a lot of information, but it's not just the SQL.
If all you want is the SQL, then you've got to write your file with
I/O functions.
Actually, there's one other choice. Create a function that returns
the .SQL property of a querydef, and then use MSysObjects as your
source table. If your function is called ReturnSQL(), the query
would look like this:
SELECT MSysObjects.Nam e, ReturnSQL([Name]) AS SQL
FROM MSysObjects
WHERE (((MSysObjects. Type)=5) AND ((MSysObjects.N ame) Not Like
"~*")) ORDER BY MSysObjects.Nam e;
(if you want the temporary queries, then you can remove the filter
on LIKE "~*")
The function looks like this:
Public Function ReturnSQL(strQu eryName As String, _
Optional db As DAO.Database) As String
Dim strTemp As String
Dim bolInitializedD B As Boolean
If db Is Nothing Then
Set db = CurrentDb()
bolInitializedD B = True
End If
strTemp = db.QueryDefs(st rQueryName).SQL
ReturnSQL = strTemp
If bolInitializedD B Then Set db = Nothing
End Function
If called only from a query based on MSysObjects, you won't need any
error handling to deal with non-existent queries, but a
general-purpose function would check to see if the query exists, or
have an error handler to recover from that condition.
Once you have a query like this, you can export it as text, if you
like.
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Very nice, thanks. But I'm not Access programmer, so I did not know
what Application.Sav eAsText would do exactly. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jb |
last post by:
Using ADO.NET from ASP.NET. Have a SqlConnection executing stuff (stored procedures)
I would like to be able to retrieve informational messages from the SQL sps, which comment on what they are doing (updating tables etc.), and show them to the user/write them to a file. Is there any way I can get at anything that comes from a SQL PRINT statement in this context? osql utility lets this go to standard output, which can be captured; that's...
|
by: Vik |
last post by:
What is a method to create a datatable containing the properties of an SQL
Server table?
Thank you.
|
by: Priya |
last post by:
hi all,
I need to read the xml schema file and retrieve the sql:datatype
element value in the xsd file.
The schema file format is below
<xsd:sequence>
<xsd:element name="safe_job" type = "xsd:string"
sql:datatype="varchar(255)" />
</xsd:sequence>
|
by: samadams_2006 |
last post by:
Hello,
How do I retrieve SQL Data into an XML Document? I have the following
code, which will retrieve SQL data and write it to the screen via the
Response Object, but I'd like to be able to read it as XML Data, and
use XSL and XSLT to display the data.
Any suggestions? Code Snippets MORE than appreciated... :)
=================================================================
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |