Thanks Vlad-this is great as is, but when I adapt it, though it is doing exactly what it is supposed to, it is corrupting the SQL for what was QryOwners.
In the adaption,
TbKingdom is TbG2ASSP where Kingdom=PartNo and ownername=ReportingObserver. There is a "DateObserved" filed too.
TbOwnername is TbObserver where Ownername=Observer
QryOwners is QryPartOutput with the following SQL
Code:
SELECT TbG2ASSP.PartNo, TbG2ASSP.ReportingObserver. TbG2ASSP.DateObserved
FROM TbG2ASSP INNER JOIN TbObserver ON TbG2ASSP.ReportingObserver = TbObserver.Observer WHERE (((TbG2ASSP. ReportingObserver Is Not Null));
And the revised VB is;
Code:
Private Sub BtnGenerate_Click()
Dim db As Database
Dim rs1 As Recordset
Dim strRunFor As String
Dim strPath As String
Dim networkPath As String
Dim sReportingObserver As String
Dim qdf As DAO.QueryDef
networkPath = "C:\My Documents\Test\"
Set db = CurrentDb
'Set rs1 = db.OpenRecordset("TbG2ASSP", dbOpenSnapshot)
Set rs1 = db.OpenRecordset("SELECT ReportingObserver FROM TbG2ASSP GROUP BY ReportingObserver HAVING (ReportingObserver Is Not Null);", dbOpenSnapshot)
Set qdf = CurrentDb.QueryDefs("QryPartOutput")
Do Until rs1.EOF
sReportingObserver = rs1("ReportingObserver")
If Len(sReportingObserver) = 0 Then GoTo Next_Record
'strPath = ReportingObserver & ".xls"
strPath = sReportingObserver & ".xls"
exportPath = networkPath & strPath
qdf.SQL = "SELECT [Part Number], [DateObserved],[ReportingObserver] FROM TbG2ASSP WHERE ReportingObserver ='" & sReportingObserver & "';"
DoCmd.OutputTo acOutputQuery, "QryPartOutput ", acFormatXLS, exportPath, False
Next_Record:
rs1.MoveNext
Loop
Set qdf = Nothing
Set rs1 = Nothing
Set db = Nothing
DoCmd.Quit
End Sub
I suspect I have an error in the ambiguous use of "Reporting Observer" in the VB. Can you tell me which line would be changing the SQL?
Really appreciate the input.
THanks,
Mattbro451