themanof83
Registered User.
- Local time
- Today, 11:42
- Joined
- May 1, 2008
- Messages
- 73
Evening All!
I am familiar with the DAO Openrecordset function when using tables. I know that the following code works when using a table but I would like to use it using a query I have saved away; as follows:
I've seen alot of posts about the unsuccesful use of Openrecordset when using Queries but haven't come accross too many work arounds...
Any help on getting this to work for pre-defined queries (as opposed to SQL statements) would be very gratefully recieved...
I am at the end of my patience with this one!!
Cheers,
I am familiar with the DAO Openrecordset function when using tables. I know that the following code works when using a table but I would like to use it using a query I have saved away; as follows:
Code:
Set MYDB = CurrentDb()
Set TARGET = MYDB.OpenRecordset(stQuery)
TARGET.MoveFirst
Do While Not TARGET.EOF
If IsNull(TARGET.Fields("Document Folder")) Then
MsgBox "There is no associated folder supplied with the test: " & TARGET.Fields("Test") & _
"Test " & TARGET.Fields("Test") & "will not be included in batch file!", vbInformation + vbOKOnly, _
"No folder supplied"
Else
If TARGET.Fields("Main") = -1 Then
PDFHyper = d.Column(2) & d.Column(3) & "\test\autotest\QTG\" & _
d.Column(5) & "\" & TARGET.Fields("Test")
End If
If TARGET.Fields("Generic") = -1 Then
PDFHyper = d.Column(2) & d.Column(3) & "\test\autotest\QTG\" & _
d.Column(6) & "\" & TARGET.Fields("Test")
End If
If TARGET.Fields("Visual") = -1 Then
PDFHyper = d.Column(2) & d.Column(3) & "\test\autotest\QTG\" & _
d.Column(7) & "\" & TARGET.Fields("Test")
End If
MyFile = d.Column(2) & d.Column(3) & "\test\AUTOTEST\batch\" & stBatchName
Debug.Print MyFile
'Open File if not already opened
If Not FileLocked(MyFile) Then
'File Number = current iteration
fnum = FreeFile()
'Open File
Open MyFile For Append As fnum
'Print to File
Print #fnum, PDFHyper
Else
'Print to File
Print #fnum, PDFHyper
End If
Close #fnum
TARGET.MoveNext
End If
Loop
'Close Query
TARGET.Close
I've seen alot of posts about the unsuccesful use of Openrecordset when using Queries but haven't come accross too many work arounds...
Any help on getting this to work for pre-defined queries (as opposed to SQL statements) would be very gratefully recieved...
I am at the end of my patience with this one!!
Cheers,