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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OutPutTo isn't available now

Status
Not open for further replies.

Dan8376

Technical User
Jan 29, 2002
25
US
I get the following error when I output two or more files in the same procedure when the database window is hidden.

Run-time error '2406'
The command or action 'OutputTo' isn't available now

If the database window is viewable then my code works fine, but when I try to "secure" the database I keep getting this error.

Any thoughts or suggestions? I know I can leave the database window viewable, but I don't like to give users a chance to mess with things.

Thanks
Dan

 
Let's see your code!

VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Here's the code, I have a sub that creates all of my reports. I call this sub from many different procedures, when I try and call this sub twice during the same procedure it errors.

'Print Sub
Sub SendReportToFile(ReportID As Long)
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim rs3 As DAO.Recordset
Dim strLoc As String
Dim strFund As String
Dim strFileName As String
Dim strReportFileName As String
Dim strReportName As String
Dim IsClient As Long
Dim IsDaily As Integer
Dim IsRevised As Integer
Dim strRevised As String
Dim dt As Date
Dim strDt As String
Dim strD As String
Dim strM As String
Dim strY As String
Set db = CurrentDb
Set rs1 = db.OpenRecordset("SELECT * FROM tblComplianceTesting")
If IsNull(rs1!TestDate) Then
MsgBox "You must enter a date before you can run this report"
Exit Sub
Else
dt = rs1!TestDate
strM = DatePart("M", dt)
If Len(strM) = 1 Then
strM = "0" & strM
End If
strD = DatePart("D", dt)
If Len(strD) = 1 Then
strD = "0" & strD
End If
strY = Right(DatePart("YYYY", dt), 2)
strDt = strM & strD & strY
End If
Set rs2 = db.OpenRecordset("SELECT * FROM tblNetworkLocations")
strLoc = rs2!ExportLoc
rs2.Close
Set rs2 = Nothing
Set rs3 = db.OpenRecordset("SELECT * FROM tblReportNames WHERE(((ReportID)= " & ReportID & "))")
If rs3.RecordCount = 0 Then
MsgBox "This report could not be found"
Exit Sub
Else
strReportName = rs3!ReportShortName
strReportFileName = rs3!FileName
IsClient = rs3!IsClientLevel
IsDaily = rs3!IsDailyCompliance
IsRevised = rs1!RevisedTest
End If
rs3.Close
Set rs3 = Nothing
If IsClient = -1 Then
strFund = ""
Else
If IsNull(rs1!TestFund) Then
MsgBox "You must select a fund before you can run this report"
Exit Sub
Else
strFund = rs1!TestFund
End If
End If
If IsRevised = -1 Then
strRevised = "_Revised"
Else
strRevised = ""
End If
strFileName = strFund & strReportFileName & strDt & strRevised
If rs1!CPUHasPDF = -1 Then
Call RunReportAsPDF(strFileName, strReportName)
Else
'<<< This is the problem line
DoCmd.OutputTo acOutputReport, strReportName, acFormatSNP, strLoc & strFileName & &quot;.snp&quot;
End If
rs1.Close
Set rs1 = Nothing
Set db = Nothing
End Sub

'Sub that calls for mulitple outputs at one time
Sub Run_FirstMarketCapReports()
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim strFund As String
Dim i As Integer
Set db = CurrentDb
Set rs1 = db.OpenRecordset(&quot;SELECT * FROM tblComplianceTesting&quot;)
Set rs2 = db.OpenRecordset(&quot;SELECT FundID, Fund, FundName, MarketCap, DailyEmail &quot; & _
&quot;FROM tblFundInfo &quot; & _
&quot;WHERE (((DailyEmail) = -1)) &quot; & _
&quot;ORDER BY Fund;&quot;)
rs2.MoveFirst
Do Until rs2.EOF
strFund = rs2!Fund
rs1.Edit
rs1!TestFund = strFund
rs1.Update
Call SendReportToFile(4)
rs2.MoveNext
Loop
rs2.Close
rs1.Close
Set rs2 = Nothing
Set rs1 = Nothing
Set db = Nothing
End Sub


Like I said before, everything runs fine if the databae window is not hidden. If its hidden, then it errors when trying to output a second report.

Thanks
Dan
 
Dan8376, Were you ever able to solve this problem? I am having the same problem and am interested in why this is happening.

Thanks,
Trevor
 
Trevor,

I don't think I did. This was a long time ago, at a different job. Sorry.

Dan
 
Try selecting the report first using:
Code:
DoCmd.SelectObject, acReport, "ReportName", True
DoCmd.OutputTo acOutputReport, strReportName, acFormatSNP, strLoc & strFileName & ".snp"
I know there are a quite a few commands that bomb if no object is selected first. Is it possible that you have mispelled a report in the tblReportNames table?

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top