I've decided to try a different direction with this.
I do not have issues with the combo boxes on the form returning the appropriate information. I have 3 reports that run from buttons on this form, and they all pass the parameters to the reports correctly and the reports are run properly.
I am, however, having an issue with this fourth button/report. It's not giving me the results I expect.
Here is the code for one of the buttons that DOES work properly:
Code:
Private Sub btnHMIRFRpt_Click()
On Error GoTo Err
If IsNull(Me.cboCompany) Then
MsgBox ("Choose a Company!")
Me.cboCompany.SetFocus
Exit Sub
End If
If IsNull(Me.cboStore) Then
MsgBox ("Choose a Store!")
Me.cboStore.SetFocus
Exit Sub
End If
DoCmd.SetWarnings False
'OpenQuery executes the Make Table query that creates the ztblHMIRFRpt table required for the HMIRF Report
DoCmd.RunSQL "Delete * From ztblHMIRFRpt;"
DoCmd.OpenQuery "qryStoreAisleQuery_CrosstabMkTbl"
DoCmd.SetWarnings True
DoCmd.OpenReport "rptHMIRF", acViewPreview, , "[StoreName] = (Select StoreName from tblStoreInformation Where StoreKey = " & Me.cboStore & ")", acWindowNormal, Me.cboStore.Value
ExitS:
DoCmd.Echo True
Exit Sub
Err:
'this error gets thrown if there is no data in the report AND the report must have the On No Data property set to CANCEL = True in the code window
'since you are going to filter the report now - if the user chooses a company or store that doesn't have records the report needs to be able to return this
If Err.Number = 2501 Then
MsgBox ("No records exist for this store/company!")
Else
MsgBox Error$
End If
End Sub
I just used the information/code for this button, and copied it to my new button, making the changes as needed:
Code:
Private Sub btnMSDSSheetsPrint_Click()
On Error GoTo btnMSDSSheetsPrint_Click_Err
If IsNull(Me.cboCompany) Then
MsgBox ("Choose a Company!")
Me.cboCompany.SetFocus
Exit Sub
End If
If IsNull(Me.cboStore) Then
MsgBox ("Choose a Store!")
Me.cboStore.SetFocus
Exit Sub
End If
DoCmd.OpenQuery "qryMSDSPrint"
DoCmd.OpenReport "rptMSDSReport", acViewPreview, , "[StoreName] = (Select StoreName from tblStoreInformation Where StoreKey = " & Me.cboStore & ")", acWindowNormal, Me.cboStore.Value
ExitS:
DoCmd.Echo True
Exit Sub
btnMSDSSheetsPrint_Click_Exit:
Exit Sub
btnMSDSSheetsPrint_Click_Err:
If Err.Number = 2501 Then
MsgBox ("No records exist for this store/company!")
Else
MsgBox Error$
End If
Resume btnMSDSSheetsPrint_Click_Exit
End Sub
I'm really confused as to why this isn't working. StoreKey is one of the fields in the query. Do I need to include StoreName in the query, too? The code here tells it to get the StoreName from the tblStoreInformation.
The results I am getting when I click the button are:
1. The results of the query (unfiltered) are shown.
2. I get a message bog "Enter Parameter Value StoreName". When I enter the name of the store (that was already chosen by the combo box on the form), I get the report showing on the screen, with the StoreName at the top of the report, but the results in the report are not filtered on StoreKey as they should be.
In case it matters, here's the code for the Query:
Code:
SELECT DISTINCT Product.MSDS, tblStoreProducts.StoreKey
FROM tblStoreInformation INNER JOIN (Product INNER JOIN tblStoreProducts ON Product.[ProductKey] = tblStoreProducts.[ProductKey]) ON tblStoreInformation.StoreKey = tblStoreProducts.StoreKey
WHERE (((tblStoreProducts.MaxUnits)<>0) AND (([Product.HazardKey])<>79))
GROUP BY Product.MSDS, tblStoreProducts.StoreKey
HAVING (((Product.MSDS) Is Not Null))
ORDER BY Product.MSDS;
I feel like I'm stuck here. I really appreciate any help someone can give me. I've checked out the various tutorials, etc. that have been posted as answers on similar threads, but haven't found anything that I believe will solve my issues.
Marcie