473,513 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I want to list saved querydefs having "tblCorrespondence" in their SQL...

MLH
I have the following code to list query names in Access 2.0's
Immediate Window. Currently, it lists names of all saved queries.
Can you suggest a modification that will result in it listing only
names of queries referencing "tblCorrespondence"?

Sub ListSavedQrys_Click ()
'************************************************* *****************
' Lists ALL the table names in the immediate window.
'
' This is useful code in many applications. Save it in template &
' refer to it whenever needed. Uses DAO.
'************************************************* *****************

On Error GoTo Err_ListSavedQrys_Click
Dim ThisForm As String
ThisForm = Me.Name

Dim MyQryDef As QueryDef, MyDatabase As Database, I As Integer,
HowManyQrys As Integer
Set MyDatabase = DBEngine.Workspaces(0).Databases(0)
Set MyQryDef = MyDatabase.CreateQueryDef("_TestOnly")
HowManyQrys = MyDatabase.QueryDefs.Count
If HowManyQrys > 99 Then
MsgBox "There are " & CStr(HowManyQrys) & " saved queries. The
immediate window will only display 99 lines."
End If
Debug.Print CStr(HowManyQrys)
Exit Sub
For I = 0 To HowManyQrys - 1
Debug.Print MyDatabase.QueryDefs(I).Name
Next I
MyDatabase.QueryDefs.Delete "_TestOnly"

Exit_ListSavedQrys_Click:
Exit Sub

Err_ListSavedQrys_Click:
Dim r As String, k As String, Message3 As String
r = "The following unexpected error occurred in Sub
ListSavedQrys_Click, CBF on " & ThisForm & "."
k = CRLF & CRLF & Str$(Err) & ": " & QUOTE & Error$ & QUOTE
Message3 = r & k
MsgBox Message3, 48, "Unexpected Error - " & MyApp$ & ", rev. " &
MY_VERSION$
Resume Exit_ListSavedQrys_Click

End Sub

Nov 13 '05 #1
14 1945
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Like this (air code):

For I = 0 To HowManyQrys - 1
If InStr(MyDatabase.QueryDefs(I).SQL, "tblCorrespondence")>0 Then
Debug.Print MyDatabase.QueryDefs(I).Name
End If
Next I

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmaCfIechKqOuFEgEQKU/wCg7kkUKXSZHRNE99HwOP24NToPU0AAoOG8
ETsSGfAs1XfuVvNbTO09vtmB
=q6do
-----END PGP SIGNATURE-----

MLH wrote:
I have the following code to list query names in Access 2.0's
Immediate Window. Currently, it lists names of all saved queries.
Can you suggest a modification that will result in it listing only
names of queries referencing "tblCorrespondence"?

Sub ListSavedQrys_Click ()
'************************************************* *****************
' Lists ALL the table names in the immediate window.
'
' This is useful code in many applications. Save it in template &
' refer to it whenever needed. Uses DAO.
'************************************************* *****************

On Error GoTo Err_ListSavedQrys_Click
Dim ThisForm As String
ThisForm = Me.Name

Dim MyQryDef As QueryDef, MyDatabase As Database, I As Integer,
HowManyQrys As Integer
Set MyDatabase = DBEngine.Workspaces(0).Databases(0)
Set MyQryDef = MyDatabase.CreateQueryDef("_TestOnly")
HowManyQrys = MyDatabase.QueryDefs.Count
If HowManyQrys > 99 Then
MsgBox "There are " & CStr(HowManyQrys) & " saved queries. The
immediate window will only display 99 lines."
End If
Debug.Print CStr(HowManyQrys)
Exit Sub
For I = 0 To HowManyQrys - 1
Debug.Print MyDatabase.QueryDefs(I).Name
Next I
MyDatabase.QueryDefs.Delete "_TestOnly"

Exit_ListSavedQrys_Click:
Exit Sub

Err_ListSavedQrys_Click:
Dim r As String, k As String, Message3 As String
r = "The following unexpected error occurred in Sub
ListSavedQrys_Click, CBF on " & ThisForm & "."
k = CRLF & CRLF & Str$(Err) & ": " & QUOTE & Error$ & QUOTE
Message3 = r & k
MsgBox Message3, 48, "Unexpected Error - " & MyApp$ & ", rev. " &
MY_VERSION$
Resume Exit_ListSavedQrys_Click

End Sub

Nov 13 '05 #2
MLH
<snip>
Like this (air code):

For I = 0 To HowManyQrys - 1
If InStr(MyDatabase.QueryDefs(I).SQL, "tblCorrespondence")>0 Then
Debug.Print MyDatabase.QueryDefs(I).Name
End If
Next I


I just knew the above was gonna work when I tried it. But, to my
surprise, it did not. I'm gonna try to find out why.
Nov 13 '05 #3
MLH
<snip>

Like this (air code):

For I = 0 To HowManyQrys - 1
If InStr(MyDatabase.QueryDefs(I).SQL, "tblCorrespondence")>0 Then
Debug.Print MyDatabase.QueryDefs(I).Name
End If
Next I


Hmmmm??? The problem must be with the .SQL specifier...
I could not even get this to print in the immediate window:

MyString = MyDatabase.QueryDefs(I).SQL
Debug.Print MyString

Nov 13 '05 #4
MLH wrote:
<snip>
Like this (air code):

For I = 0 To HowManyQrys - 1
If InStr(MyDatabase.QueryDefs(I).SQL, "tblCorrespondence")>0 Then
Debug.Print MyDatabase.QueryDefs(I).Name
End If
Next I

Hmmmm??? The problem must be with the .SQL specifier...
I could not even get this to print in the immediate window:

MyString = MyDatabase.QueryDefs(I).SQL
Debug.Print MyString


I'm not familiar w/ Access 2.0, so maybe the .SQL property of the
QueryDefs wasn't available in that version. My earliest version was '95.

When you say it's not working, what is it doing instead - error,
nothing? If an error, which one?
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Nov 13 '05 #5
SQL.Property surely is available in Access 2.0
This wil print out the SQL-string in the Immediate window:
Sub test ()
Set Db = dbEngine(0)(0)
Debug.Print Db.QueryDefs("MyQueryName").SQL
End Sub

--
Hope this helps
Arno R
"MGFoster" <me@privacy.com> schreef in bericht news:%c*******************@newsread1.news.pas.eart hlink.net...
MLH wrote:
<snip>
Like this (air code):

For I = 0 To HowManyQrys - 1
If InStr(MyDatabase.QueryDefs(I).SQL, "tblCorrespondence")>0 Then
Debug.Print MyDatabase.QueryDefs(I).Name
End If
Next I



Hmmmm??? The problem must be with the .SQL specifier...
I could not even get this to print in the immediate window:

MyString = MyDatabase.QueryDefs(I).SQL
Debug.Print MyString


I'm not familiar w/ Access 2.0, so maybe the .SQL property of the
QueryDefs wasn't available in that version. My earliest version was '95.

When you say it's not working, what is it doing instead - error,
nothing? If an error, which one?
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

Nov 13 '05 #6
MLH
On Thu, 21 Apr 2005 02:28:11 GMT, MGFoster <me@privacy.com> wrote:
MLH wrote:
<snip>
Like this (air code):

For I = 0 To HowManyQrys - 1
If InStr(MyDatabase.QueryDefs(I).SQL, "tblCorrespondence")>0 Then
Debug.Print MyDatabase.QueryDefs(I).Name
End If
Next I

Hmmmm??? The problem must be with the .SQL specifier...
I could not even get this to print in the immediate window:

MyString = MyDatabase.QueryDefs(I).SQL
Debug.Print MyString


I'm not familiar w/ Access 2.0, so maybe the .SQL property of the
QueryDefs wasn't available in that version. My earliest version was '95.

When you say it's not working, what is it doing instead - error,
nothing? If an error, which one?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Strangely enough, its not returning an error. What does display is the
last value of i on a line by itself.
Nov 13 '05 #7
MLH
<snip>
SQL.Property surely is available in Access 2.0
This wil print out the SQL-string in the Immediate window:
Sub test ()
Set Db = dbEngine(0)(0)
Debug.Print Db.QueryDefs("MyQueryName").SQL
End Sub


Thx for the suggestion. I tried to implement your idea this way:
For I = 0 To HowManyQrys - 1
If InStr(MyDatabase.QueryDefs(I).SQL, "tblCorrespondence") > 0
MyName = MyDatabase.QueryDefs(I).Name
Debug.Print MyDatabase.QueryDefs(MyName).SQL
End If
Next I

Doesn't work for me. Could it be a timing issue? Hard to imagine.
Nov 13 '05 #8
"MLH" <CR**@NorthState.net> schreef in bericht news:8f********************************@4ax.com...
<snip>
SQL.Property surely is available in Access 2.0
This wil print out the SQL-string in the Immediate window:
Sub test ()
Set Db = dbEngine(0)(0)
Debug.Print Db.QueryDefs("MyQueryName").SQL
End Sub


Thx for the suggestion. I tried to implement your idea this way:
For I = 0 To HowManyQrys - 1
If InStr(MyDatabase.QueryDefs(I).SQL, "tblCorrespondence") > 0
MyName = MyDatabase.QueryDefs(I).Name
Debug.Print MyDatabase.QueryDefs(MyName).SQL
End If
Next I

Doesn't work for me. Could it be a timing issue? Hard to imagine.


Well the code works for me. Perfectly...

You DID adapt the aircode MGFoster gave you?
You did NOT only use the code as you posted I hope?

Sorry if I ask the obvious ... just trying to be sure.

Arno R
Nov 13 '05 #9
MLH wrote:
<snip>
SQL.Property surely is available in Access 2.0
This wil print out the SQL-string in the Immediate window:
Sub test ()
Set Db = dbEngine(0)(0)
Debug.Print Db.QueryDefs("MyQueryName").SQL
End Sub

Thx for the suggestion. I tried to implement your idea this way:
For I = 0 To HowManyQrys - 1
If InStr(MyDatabase.QueryDefs(I).SQL, "tblCorrespondence") > 0
MyName = MyDatabase.QueryDefs(I).Name
Debug.Print MyDatabase.QueryDefs(MyName).SQL
End If
Next I

Doesn't work for me. Could it be a timing issue? Hard to imagine.


Can one set a reference to ADO in Access 2? I don't know, but if so then
I would do so and then try: (Probably I'd have to hard code the
connection string).

Dim r As ADODB.Recordset
Set r = CurrentProject.Connection.OpenSchema(adSchemaViews )
With r
Do While Not .EOF
If InStr(.Fields("VIEW_DEFINITION"), "Classes") <> 0 Then
Debug.Print .Fields("TABLE_NAME"), .Fields("VIEW_DEFINITION")
End If
.MoveNext
Loop
End With

--
--
Lyle

"The aim of those who try to control thought is always the same. They
find one single explanation of the world, one system of thought and
action that will (they believe) cover everything; and then they try to
impose that on all thinking people."
- Gilbert Highet
Nov 13 '05 #10
Hi Lyle,
Can one set a reference to ADO in Access 2? I don't know, but if so then
I would do so and then try: (Probably I'd have to hard code the
connection string).


NO ADO in Access 2.0 So that's not an option.
No need to either. The code as given by MGFoster works.

Arno R

Btw: Thx ! (you know why ...)
Sometimes it looks like "much ADO about nothing"
Nov 13 '05 #11
MLH
<snip>

Doesn't work for me. Could it be a timing issue? Hard to imagine.


Well the code works for me. Perfectly...

You DID adapt the aircode MGFoster gave you?
You did NOT only use the code as you posted I hope?

Sorry if I ask the obvious ... just trying to be sure.

Arno R

xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I probably screwed it up. Will try again.
Nov 13 '05 #12
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I probably screwed it up. Will try again.


Hi MLH
Sorry for this late reaction. My newsserver is completely down since 3 day allready ...

Just wondered if your code works now.
If not, I can post the complete code

Arno R
Nov 13 '05 #13
MLH
Thx for the offer.
Please post. I had
no luck & gave up
on it. Renewed
interest, though.
Thx.

xxxxxxxxxxxxxxxxxxxxxx

Hi MLH
Sorry for this late reaction. My newsserver is completely down since 3 day allready ...

Just wondered if your code works now.
If not, I can post the complete code

Arno R


Nov 13 '05 #14

"MLH" <CR**@NorthState.net> schreef in bericht news:u0********************************@4ax.com...
Thx for the offer.
Please post. I had
no luck & gave up
on it. Renewed
interest, though.
Thx.

xxxxxxxxxxxxxxxxxxxxxx

Hi MLH
Sorry for this late reaction. My newsserver is completely down since 3 day allready ...

Just wondered if your code works now.
If not, I can post the complete code

Arno R


I don't remember what this code was about ..
Could you post your not-working-code, or ask your question again?

Arno R
Nov 13 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1900
by: MLH | last post by:
I have a query, qryAppend30DayOld260ies that attempts to append records to tblCorrespondence. When run, it can result in any of the following: appending no records, appending 1 record or appending...
6
1474
by: MLH | last post by:
I have a table - tblCorrespondence. It houses records of correspondence initiated here in our office. Records are appended whenever it is recognized that some type of outbound letter needs to be...
2
2246
by: MLH | last post by:
Consider having tblCorrespondence, then copying & pasting it to tblCorrespondence1 - such that they are identical. Then consider the following UNION SELECT statement... SELECT...
22
10255
by: MLH | last post by:
100 Dim db As Database, rst As Recordset 120 Set db = CurrentDb 140 PString = "SELECT qryBatchList.ReadyFor906, qryBatchList.BatchID FROM qryBatchList WHERE...
0
7257
marktang
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,...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
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,...
0
7521
tracyyun
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...
0
5682
agi2029
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,...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
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...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
455
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.