J
Jeff C
I need help understanding the difference between how to declare either a TEXT
or Integer as a parameter.
"[Forms]![FRpts].[Unit]" based on QFAC is used as criteria in Q_ExpRpt.
The function below works when using "[Forms]![FRpts].[fName]" where fName is
text and I enclose the criteria in quotes.
I cannot get it to work where "Unit" is used - Unit is an Integer.
Option Compare Database
Option Explicit
Public Function ExpRpt()
Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Dim rstFAC As DAO.Recordset
Dim strSQL As String, strTemp As String, strQReportSQL As String
Dim strfac As String
Dim strBookName As String
Const strQName As String = "zExpRptQry"
Const strQReportParameterName As String = "[Forms]![FRpts].[Unit]"
DoCmd.SetWarnings False
Set dbs = CurrentDb
strQReportSQL = dbs.QueryDefs("Q_ExpRpt").SQL
Set qdf = dbs.CreateQueryDef(strQName, strQReportSQL)
qdf.Close
strTemp = qdf.Name
Set qdf = Nothing
Set rstFAC = dbs.OpenRecordset("QFAC", dbOpenDynaset, dbReadOnly)
If rstFAC.EOF = False And rstFAC.BOF = False Then
rstFAC.MoveFirst
Do While rstFAC.EOF = False
strfac = CStr(rstFAC![ID])
strBookName = CStr(rstFAC![FacilityNameSubUnit])
strSQL = Replace(strQReportSQL, strQReportParameterName,
strfac, 1, -1, vbTextCompare)
Set qdf = dbs.QueryDefs(strTemp)
qdf.Name = "q_" & strfac
strTemp = qdf.Name
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
strTemp, "C:\ExpReports\" & strBookName & ".xls"
rstFAC.MoveNext
Loop
End If
rstFAC.Close
Set rstFAC = Nothing
dbs.QueryDefs.Delete strTemp
dbs.Close
Set dbs = Nothing
DoCmd.SetWarnings True
End Function
Any assistance appreciated - Thanks
or Integer as a parameter.
"[Forms]![FRpts].[Unit]" based on QFAC is used as criteria in Q_ExpRpt.
The function below works when using "[Forms]![FRpts].[fName]" where fName is
text and I enclose the criteria in quotes.
I cannot get it to work where "Unit" is used - Unit is an Integer.
Option Compare Database
Option Explicit
Public Function ExpRpt()
Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Dim rstFAC As DAO.Recordset
Dim strSQL As String, strTemp As String, strQReportSQL As String
Dim strfac As String
Dim strBookName As String
Const strQName As String = "zExpRptQry"
Const strQReportParameterName As String = "[Forms]![FRpts].[Unit]"
DoCmd.SetWarnings False
Set dbs = CurrentDb
strQReportSQL = dbs.QueryDefs("Q_ExpRpt").SQL
Set qdf = dbs.CreateQueryDef(strQName, strQReportSQL)
qdf.Close
strTemp = qdf.Name
Set qdf = Nothing
Set rstFAC = dbs.OpenRecordset("QFAC", dbOpenDynaset, dbReadOnly)
If rstFAC.EOF = False And rstFAC.BOF = False Then
rstFAC.MoveFirst
Do While rstFAC.EOF = False
strfac = CStr(rstFAC![ID])
strBookName = CStr(rstFAC![FacilityNameSubUnit])
strSQL = Replace(strQReportSQL, strQReportParameterName,
strfac, 1, -1, vbTextCompare)
Set qdf = dbs.QueryDefs(strTemp)
qdf.Name = "q_" & strfac
strTemp = qdf.Name
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
strTemp, "C:\ExpReports\" & strBookName & ".xls"
rstFAC.MoveNext
Loop
End If
rstFAC.Close
Set rstFAC = Nothing
dbs.QueryDefs.Delete strTemp
dbs.Close
Set dbs = Nothing
DoCmd.SetWarnings True
End Function
Any assistance appreciated - Thanks