It definitely has something to do with the syntax of the WHERE statement. I tried every combination I know, which isn't much. I commented out the SQL assignment statement and ran it with the existing querydef and it opened the report.
I made quite a few changes. I had the queries backward, but I still get the type mismatch error.
Here is the SQL statement from
qryDL-MassPrint
SELECT qryCustomers.CustomerID, qryDLNetPricing.Model, qryDLNetPricing.Size, qryDLNetPricing.DLNetPrice, qryCustomers.CompanyName, qryCustomers.MailAddress, qryCustomers.MailCity, qryCustomers.MailState, qryCustomers.MailZip, qryCustomers.ShipAddress, qryCustomers.ShipCity, qryCustomers.ShipState, qryCustomers.ShipZip, qryCustomers.Phone, qryCustomers.ProdGroupChoice, qryCustomers.ProdGroupChoice2, qryCustomers.ProdGroupChoice3, qryCustomers.ProdGroupChoice4, qryCustomers.Terms, qryCustomers.Freight, qryCustomers.Allowances, qryCustomers.Notes, qryCustomers.EffectiveDate, qryDLNetPricing.ID
FROM qryDLNetPricing INNER JOIN qryCustomers ON qryDLNetPricing.CustomerID = qryCustomers.CustomerID
WHERE (((qryCustomers.CustomerID)="05073"));
Here is the modified code:
Private Sub btnDLPrint_Click()
On Error GoTo Err_btnDLPrint_Click
Dim stDocName As String
Dim rst As Recordset
Dim strSql As String
' Open Recordset and print report.
' Open Recordset
Set rst = CurrentDb.OpenRecordset("qryCustomerDetail")
With rst
.MoveFirst
While Not rst.EOF
strSql = "SELECT qryCustomers.CustomerID, qryDLNetPricing.Model, "
strSql = strSql & "qryDLNetPricing.Size, qryDLNetPricing.DLNetPrice, "
strSql = strSql & "qryCustomers.CompanyName, qryCustomers.MailAddress, "
strSql = strSql & "qryCustomers.MailCity, qryCustomers.MailState, "
strSql = strSql & "qryCustomers.MailZip, qryCustomers.ShipAddress, "
strSql = strSql & "qryCustomers.ShipCity, qryCustomers.ShipState, "
strSql = strSql & "qryCustomers.ShipZip, qryCustomers.Phone, "
strSql = strSql & "qryCustomers.ProdGroupChoice, "
strSql = strSql & "qryCustomers.ProdGroupChoice2, "
strSql = strSql & "qryCustomers.ProdGroupChoice3, "
strSql = strSql & "qryCustomers.ProdGroupChoice4, "
strSql = strSql & "qryCustomers.Terms, qryCustomers.Freight, "
strSql = strSql & "qryCustomers.Allowances, qryCustomers.Notes, "
strSql = strSql & "qryCustomers.EffectiveDate, qryDLNetPricing.ID "
strSql = strSql & "FROM qryDLNetPricing "
strSql = strSql & "INNER JOIN qryCustomers "
strSql = strSql & "ON qryDLNetPricing.CustomerID = qryCustomers.CustomerID "
strSql = strSql & "WHERE (((qryCustomers.CustomerID)='" & rst!CustomerID & "'
);"
'qryCustomerDLNetPricing is the query that the report is based on
CurrentDb.QueryDefs("qryDL-MassPrint").SQL = strSql
stDocName = "rptCustomerNetPrices-DL-MassPrint"
' Print the report for current record
DoCmd.OpenReport stDocName, acViewPreview, "qryDL-MassPrint"
.MoveNext
Wend
End With
rst.Close
Set rst = Nothing
Exit_btnDLPrint_Click:
Exit Sub
Err_btnDLPrint_Click:
MsgBox Err.Description
Resume Exit_btnDLPrint_Click