Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thank you again! I can't tell you how much I and my company appreciate what you've done! I love this place!..."

Geography

Where in the world do Tek-Tips members come from?

Print a few records from each table in a Access db

KevinsHandle (Programmer)
15 May 12 21:46
I want to iterate thru TDFs, set a strSQL to get the top 5 records, open and print the query result and move on to the next TDF. I have code for looping the TDFs but after opening the query how do I print it and close it ? Thanks.
Remou (TechnicalUser)
16 May 12 11:11
Some notes.

CODE

Dim qdf As QueryDef Dim tdf As TableDef Dim db As Database Set db = CurrentDb Set tdf = db.TableDefs("Table1") sSQL = "SELECT * FROM [" & tdf.Name & "]" If DLookup("Name", "MSysObjects", "Name='TempQry'") = Null Then CurrentDb.CreateQueryDef "TempQry", sSQL Else CurrentDb.QueryDefs("TempQry").sql = sSQL End If DoCmd.OpenQuery "TempQry" DoCmd.RunCommand acCmdQuickPrint DoCmd.Close acQuery, "TempQry"

http://lessthandot.com

KevinsHandle (Programmer)
16 May 12 11:28
Here is the quick and dirty code that I usedto find my data.

Sub SampleData()
'**********************************************
'*This is designed to walk the table definitions in an access db
'*and print out the top five records from each similarly named
'*table. you could change the IF condition to do groups of tables
'*All tables or all but system tables
'
' Needed this because some soul rearanged server level source tables
' and schema without notice
'**********************************************
Dim db As Database
Dim qdfnew As QueryDef
Dim strSQL As String
Dim lngTable As Long
Set db = CurrentDb
For lngTable = 0 To db.TableDefs.Count - 1
If db.TableDefs(lngTable).Name Like "tblT*" Then
strSQL = "Select Top 5 " & db.TableDefs(lngTable).Name & ".* FROM " & db.TableDefs(lngTable).Name & ";"
With CurrentDb
.QueryDefs.Delete ("qryGetFileSample")
Set qdfnew = .CreateQueryDef("qryGetFileSample", strSQL)
.Close
End With
Debug.Print strSQL
DoCmd.OpenQuery ("qrygetfilesample")
DoCmd.PrintOut acPrintAll
DoCmd.Close acQuery, "qrygetfilesample"
End If
Next lngTable
End Sub

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close