B
Brad
Thanks for taking the time to read my question.
I am opening a report, but want to check if there is data
for the report first. I have this working on another
report, but I am having troubles with my querydefn. I
get the error "Expected 2" when I run my code. I have
put the code and the SQL of the query below.
My question is: What is my second querydefn? I have
tried pasting the iif statement - IIf([tblPurchases]!
[PurchaseStatus]=1,"Open",IIf([tblPurchases]!
[PurchaseStatus]=2,"Incomplete","Complete")) - from the
PurchaseStatusText field, but that doesn't seem to work.
The code can't find the field [tblPurchases]. If I take
that out, it can't find the field [PurchaseStatus].
I've also tried - IIf([qdf]![PurchaseStatus]=1,"Open",IIf
([qdf]![PurchaseStatus]=2,"Incomplete","Complete"))
Thanks again for the help.
Brad
CODE:
Private Sub Report_Open(Cancel As Integer)
Dim dbs As Database, rst As Recordset
Dim qdf As QueryDef
Dim RecNum As Integer
RecNum = 0
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qryProfitLoss")
qdf.Parameters(0).Value = [Forms]!
[frmReportGenerator]![StartDate] And [Forms]!
[frmReportGenerator]![EndDate]
qdf.Parameters(1).Value = 'Something Needs to go here
Set rst = qdf.OpenRecordset()
If Not rst.EOF Then
rst.MoveFirst
Do Until RecNum = 1
RecNum = RecNum + 1
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
Set dbs = Nothing
If RecNum = 0 Then
DoCmd.Close
MsgBox "No data available for this report." & Chr
(13) & Chr(13) & "You have tried to open the Profit Loss
Report. No Sales have occurred. Use this report when a
transaction has been fully or partially completed.", 48
End If
End Sub
SQL of Query:
SELECT tblPurchases.PurchaseTransactionID,
tblPurchases.PurchaseDate, tblPurchases.StockName,
tblPurchases.StockCode,
tblPurchases.TransactionCompletedBy,
tblPurchases.PurchaseAmount, tblPurchases.PurchasePrice,
tblPurchases.PurchaseFee, IIf([tblPurchases]!
[PurchaseStatus]=1,"Open",IIf([tblPurchases]!
[PurchaseStatus]=2,"Incomplete","Complete")) AS
PurchaseStatusText, tblSales.SaleDate,
tblSales.SaleAmount, tblSales.SalePrice,
tblSales.SaleFee,
qryProfitLossAllTotals.ProfitLossAllTotals
FROM (tblPurchases INNER JOIN qryProfitLossAllTotals ON
tblPurchases.PurchaseTransactionID =
qryProfitLossAllTotals.qryProfitLossDLookupPreA.PurchaseTr
ansactionID) INNER JOIN tblSales ON
tblPurchases.PurchaseTransactionID =
tblSales.PurchaseTransactionID
WHERE (((tblPurchases.PurchaseDate) Between [Forms]!
[frmReportGenerator]![StartDate] And [Forms]!
[frmReportGenerator]![EndDate]))
ORDER BY tblPurchases.PurchaseDate,
tblPurchases.StockName;
I am opening a report, but want to check if there is data
for the report first. I have this working on another
report, but I am having troubles with my querydefn. I
get the error "Expected 2" when I run my code. I have
put the code and the SQL of the query below.
My question is: What is my second querydefn? I have
tried pasting the iif statement - IIf([tblPurchases]!
[PurchaseStatus]=1,"Open",IIf([tblPurchases]!
[PurchaseStatus]=2,"Incomplete","Complete")) - from the
PurchaseStatusText field, but that doesn't seem to work.
The code can't find the field [tblPurchases]. If I take
that out, it can't find the field [PurchaseStatus].
I've also tried - IIf([qdf]![PurchaseStatus]=1,"Open",IIf
([qdf]![PurchaseStatus]=2,"Incomplete","Complete"))
Thanks again for the help.
Brad
CODE:
Private Sub Report_Open(Cancel As Integer)
Dim dbs As Database, rst As Recordset
Dim qdf As QueryDef
Dim RecNum As Integer
RecNum = 0
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qryProfitLoss")
qdf.Parameters(0).Value = [Forms]!
[frmReportGenerator]![StartDate] And [Forms]!
[frmReportGenerator]![EndDate]
qdf.Parameters(1).Value = 'Something Needs to go here
Set rst = qdf.OpenRecordset()
If Not rst.EOF Then
rst.MoveFirst
Do Until RecNum = 1
RecNum = RecNum + 1
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
Set dbs = Nothing
If RecNum = 0 Then
DoCmd.Close
MsgBox "No data available for this report." & Chr
(13) & Chr(13) & "You have tried to open the Profit Loss
Report. No Sales have occurred. Use this report when a
transaction has been fully or partially completed.", 48
End If
End Sub
SQL of Query:
SELECT tblPurchases.PurchaseTransactionID,
tblPurchases.PurchaseDate, tblPurchases.StockName,
tblPurchases.StockCode,
tblPurchases.TransactionCompletedBy,
tblPurchases.PurchaseAmount, tblPurchases.PurchasePrice,
tblPurchases.PurchaseFee, IIf([tblPurchases]!
[PurchaseStatus]=1,"Open",IIf([tblPurchases]!
[PurchaseStatus]=2,"Incomplete","Complete")) AS
PurchaseStatusText, tblSales.SaleDate,
tblSales.SaleAmount, tblSales.SalePrice,
tblSales.SaleFee,
qryProfitLossAllTotals.ProfitLossAllTotals
FROM (tblPurchases INNER JOIN qryProfitLossAllTotals ON
tblPurchases.PurchaseTransactionID =
qryProfitLossAllTotals.qryProfitLossDLookupPreA.PurchaseTr
ansactionID) INNER JOIN tblSales ON
tblPurchases.PurchaseTransactionID =
tblSales.PurchaseTransactionID
WHERE (((tblPurchases.PurchaseDate) Between [Forms]!
[frmReportGenerator]![StartDate] And [Forms]!
[frmReportGenerator]![EndDate]))
ORDER BY tblPurchases.PurchaseDate,
tblPurchases.StockName;