Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old April 9th, 2006, 08:25 PM
MLH
Guest
 
Posts: n/a
Default Want a procedure to list saved qry fieldnames to immediate window

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

  #2  
Old April 10th, 2006, 02:55 AM
pietlinden@hotmail.com
Guest
 
Posts: n/a
Default Re: Want a procedure to list saved qry fieldnames to immediate window

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

  #3  
Old April 10th, 2006, 03:25 PM
Jeremy Wallace
Guest
 
Posts: n/a
Default Re: Want a procedure to list saved qry fieldnames to immediate window

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

  #4  
Old April 10th, 2006, 05:15 PM
Phil Latio
Guest
 
Posts: n/a
Default Re: Want a procedure to list saved qry fieldnames to immediate window

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:[color=blue]
> 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[/color]

  #5  
Old April 10th, 2006, 06:15 PM
Jeremy Wallace
Guest
 
Posts: n/a
Default Re: Want a procedure to list saved qry fieldnames to immediate window

Phil,

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

Jeremy

  #6  
Old April 11th, 2006, 12:45 AM
Bob Quintal
Guest
 
Posts: n/a
Default Re: Want a procedure to list saved qry fieldnames to immediate window

"Jeremy Wallace" <jeremygetsmail@gmail.com> wrote in
news:1144688555.103740.168070@u72g2000cwu.googlegr oups.com:
[color=blue]
> Phil,
>
> Try to compile the code. Does it compile for you? It didn't
> for me.
>
> Jeremy
>[/color]
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.
  #7  
Old April 11th, 2006, 04:55 PM
Jeremy Wallace
Guest
 
Posts: n/a
Default Re: Want a procedure to list saved qry fieldnames to immediate window

Yeah, or declare the variable!

  #8  
Old April 11th, 2006, 11:15 PM
Bob Quintal
Guest
 
Posts: n/a
Default Re: Want a procedure to list saved qry fieldnames to immediate window

"Jeremy Wallace" <jeremygetsmail@gmail.com> wrote in
news:1144770335.923439.102280@t31g2000cwb.googlegr oups.com:
[color=blue]
> Yeah, or declare the variable!
>[/color]
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.
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles