Return Recordset based on a query from a different Database

L

Lynn

I have two different databases, one is in my local
machime, and the other one is in a different drive "called
Network". I'd like to pick a query's name from a table
that list all the name of queries in the local machine,
and that name would call a select query that listed on the
Network's database, then it would run and return "display"
the result of that query. Below here is my code, it's work
but it doesnot display the result.

Function ProcessQueries ()

Dim db As Database, rs As Recordset, qd As QueryDef
Dim qname As String, QueryCount As Integer, LoopControl As
Integer, FileDir As String
Dim SQL As String, rc%, providernum

FileDir = "\\dl1\G$\Network\INTEG\Queries.mdb"

'Initialize variables
qname = "": Query1 = "": Query2 = "": Query3 = ""
Query4 = "": Query5 = "": Query6 = "": QueryName = ""
SortCol = Null: WordMergeTable = ""


'Get the complete record for the selected query
SQL = "Select * from ProductionReports where QueryID
= " & Forms![frmProductionReports]![cboReport].Column(0)


Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset(SQL)

If rs.RecordCount = 0 Then GoTo PQ_Error

If Not IsNull(rs.Query1) Then Query1 = rs.Query1
If Not IsNull(rs.Query2) Then Query2 = rs.Query2
If Not IsNull(rs.Query3) Then Query3 = rs.Query3
If Not IsNull(rs.Query4) Then Query4 = rs.Query4
If Not IsNull(rs.Query5) Then Query5 = rs.Query5
If Not IsNull(rs.Query6) Then Query6 = rs.Query6
QueryCount = CInt(rs.QueryCount)
'ReportOnlyFlag = rs.ReportOnlyFlag
QueryName = rs.QueryName
SortCol = rs.SortColumn
If rs.WordMerge = "-1" Then WordMergeTable =
rs.TableToMerge
rs.Close
db.Close



'If the Query Count is 1 then the only query to be run is
the
'reports underlying select query. Therefore, there is no
need to run
'an queries in the code here.
If QueryCount = 1 Then
qname = Query1
GoTo PQ_RunReport
End If
PQ_RunReport
Set db = DBEngine.Workspaces(0).OpenDatabase(FileDir)
Set qd = db.QueryDefs(qname)
Set rs = db.OpenRecordset(DB_OPEN_DYNASET)
rs.Close
qd.Close
db.Close
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top