473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Want a procedure to list saved qry fieldnames to immediate window

MLH
I use this to list table fieldnames to the debug window.
Can it be modified to perform similar objective for saved
query objects? Would it be best to trash this completely
and write a procedure for queries from scratch?

Private Sub ListFieldsBttn_Click()
'*********************************************
' Prompt user for the table name. List the
' [FieldName]s in the immediate window.
'*********************************************
Dim MyDB As Database, MyData As Recordset
Dim TempRecordset As Recordset, i As Integer
Dim j As Integer, Msg As String, Title As String
Dim Defvalue As String, Answer As String
Dim PString As String
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Msg = "Enter table name."
Title = "Table Name?"
Defvalue = "Notes4PHPMySQLprgmmr"
Answer = InputBox$(Msg, Title, Defvalue)
If Answer = "" Then Exit Sub
Set MyData = MyDB.OpenRecordset(Answer, DB_OPEN_SNAPSHOT)
Debug.Print
For j = 0 To MyDB.Recordsets.Count - 1
Set TempRecordset = MyDB.Recordsets(j)
HowManyFields = TempRecordset.Fields.Count
If HowManyFields > 99 Then
PString = "There are " & CStr(HowManyFields)
PString = PString & " fields. Remember, the "
PString = PString & "immediate window will only "
PString = PString & "display 99 lines."
MsgBox PString
End If
Debug.Print
Debug.Print
Debug.Print "Fields in "; TempRecordset.Name & ":"
Debug.Print
For i = 0 To TempRecordset.Fields.Count - 1
Debug.Print TempRecordset.Fields(i).Name
Next i
Next j
MyData.Close

End Sub

Apr 9 '06 #1
7 1855
the querydef object has a fields collection too. So yes, you can.
Something along the lines of:

for intCounter = 0 to qdf.Fields.Count
debug.print qdf.fields(intCounter).Name
next intCounter

Apr 10 '06 #2
Did you even try this? Aside from not having one variable declared,
this same code works just fine for a query, too.

This newsgroup is a pretty good resource, but you'll find people are
much more responsive here if you've shown some initiative yourself and
tried to putter around a bit figuring things out yourself. It's best to
try a few things and report on what you've tried and what's worked or
not worked, and what exactly went wrong when things didn't work.

If you'd tried this with a query you'd have gotten exactly the results
you were looking for.

Jeremy

Apr 10 '06 #3
Hi Jeremy

Could you clarify "Aside from not having one variable declared....."
I'm confused to your response, as within the code I can see the
varaibles declared.

Thanks

Phil
Jeremy Wallace wrote:
Did you even try this? Aside from not having one variable declared,
this same code works just fine for a query, too.

This newsgroup is a pretty good resource, but you'll find people are
much more responsive here if you've shown some initiative yourself and
tried to putter around a bit figuring things out yourself. It's best to
try a few things and report on what you've tried and what's worked or
not worked, and what exactly went wrong when things didn't work.

If you'd tried this with a query you'd have gotten exactly the results
you were looking for.

Jeremy


Apr 10 '06 #4
Phil,

Try to compile the code. Does it compile for you? It didn't for me.

Jeremy

Apr 10 '06 #5
"Jeremy Wallace" <je************@gmail.com> wrote in
news:11**********************@u72g2000cwu.googlegr oups.com:
Phil,

Try to compile the code. Does it compile for you? It didn't
for me.

Jeremy

Remove the "option explicit" from the module's header and it
compiles fine.

Note to MLH: put a checkmark to Tools->Options...=>Require Variable
Declaration

--
Bob Quintal

PA is y I've altered my email address.
Apr 10 '06 #6
Yeah, or declare the variable!

Apr 11 '06 #7
"Jeremy Wallace" <je************@gmail.com> wrote in
news:11**********************@t31g2000cwb.googlegr oups.com:
Yeah, or declare the variable!

I told MLH to fix that problem.
But I responded the way I did because removing the option explicit
allows the code as posted to compile.

Having option explicit is a good debugging technique in that
undeclared variables get caught. In my experience, typos in
variable names is a much larger problem than logic errors..

proper indenting, explicit variable declarations and /1 automatic
conditional closure are very good ways of saving time.

/1 I wish Access did this like Brief did it. Type IF x Then (CR)
and Brief inserted the next line with End If.
Type FOR x = 1 to 2 (CR) and Next x appeared below.

--
Bob Quintal

PA is y I've altered my email address.
Apr 11 '06 #8

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

Similar topics

5
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality...
14
by: MLH | last post by:
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...
6
by: Miles Keaton | last post by:
Is there a simple way to list fieldnames in a table, from PHP? When on the command-line, I just do \d tablename But how to get the fieldnames from PHP commands? ...
1
by: platostoteles | last post by:
Hallo NG, I am new to JavaScript and would really appreciate any help to solve my problem. I am using the blow code in my form to validate form fields. What I would like to accomplish is that...
6
by: sghi | last post by:
Hi All, I'm new to this group and quite new to access/vba. So, shortly after beginning to write a simple application for my wife, I came across a blocking problem: I need to intercept the sql...
5
by: vul | last post by:
In VB6 I used to use Immediate Window to get or change values of variables. It is very convenient while debugging. I used drag and drop operation to paste the variable name into Immediate Window....
1
by: fbk2k5 | last post by:
hi i have a problem to connect the user inside the stored procedure in oracle i tried option CREATE OR REPLACE PROCEDURE Chk_Permission AS UserID VARCHAR2(10):='1234'; fname...
6
by: Frank Rizzo | last post by:
I am using the Immediate Window a lot to see the progress of the application. In VS2003, if your cursor was at the very bottom, the window would scroll down whenever something new showed up. If...
13
by: Neil | last post by:
Can I get the name of a procedure from within the procedure? In my error handler, I write the error to an error table. I'd like to write the name of the procedure that's writing the error. But,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.