Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running multiply queries - wondering where to output result 1

Status
Not open for further replies.

teqtaq

Technical User
Nov 18, 2007
197
US
I am running compliance querie - 12 different queries.
I want to put them in a Function and run one by one - which I did.

Now I am thinking - even most of them come up with no result (which is good) - some of them sometimes come with result and I want to autamate it but IF result is <>Null - I want to see it.

What would be the approach to have it done?
I am luck of logic here.
I could create a table and have it write intot he table but format is so different for each. I am stuck, please, push me into right direction.
Thanks
 
Could be a good idea. I will test it now. Thanks
 
I found code

Dim fs, f
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile("c:\test.txt", True)
f.WriteLine ("Hello World!")
f.Close
Set f = Nothing
Set fs = Nothing

However it is not clear to me - where should I put the code?
I have
docmd.openquery "1"
docmd.openquery "2"
docmd.openquery "3"
docmd.openquery "4" etc

and if one comes up with result - code should start but I am not sure how to do this.

Thanks


 
Instead of opening the queries, use them for recordsets.

Some notes.


Code:
    Const ForAppending = 8
    Dim strPath As String
    Dim rs As DAO.Recordset
    
    strPath = CurrentProject.PATH
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    If fs.FileExists(strPath & "\ErrorLog.txt") = True Then
        Set a = fs.OpenTextFile(strPath & "\ErrorLog.txt", ForAppending)
    Else
        Set a = fs.CreateTextFile(strPath & "\ErrorLog.txt")
    End If
    a.WriteLine Date
    Set rs = CurrentDb.OpenRecordset("Query10")
    
    If Not rs.EOF Then
        Do While Not rs.EOF
            For i = 0 To rs.Fields.Count - 1
                aline = aline & " " & rs(i)
            Next
            
            a.WriteLine aline
            rs.MoveNext
            aline = ""
        Loop
    End If
    a.Close


 
It is complex but thanks so much!
I will try and hope it'll work for me.
THANKS
 
How is that suppose to be done:"Instead of opening the queries, use them for recordsets."

Should I be pasting this code 12 times and changing "Query10" to name of each query?
 
...
a.WriteLine Date
For Each strQryName In Array("query1", ..., "query12")
Set rs = CurrentDb.OpenRecordset(strQryName)
Do While Not rs.EOF
For i = 0 To rs.Fields.Count - 1
aline = aline & " " & rs(i)
Next
a.WriteLine aline
rs.MoveNext
aline = ""
Loop
rs.Close
Next
a.Close

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

Consider also adding each query into a UNION (assuming the same columns are possible). You can cut down on saved queries by adding the full SQL for each, rather than referencing the individual 12 queries, but it makes debugging really difficult.

You can then view the results of the union query in a form or report.

SeeThru
Synergy Connections Ltd - Telemarketing Services

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top