C
Craig
I have a Query by Form , with a button that runs a macro and opens a
document.
The document is opened through a module.
-----------------------------------------------------------------------
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Set db = CurrentDb
Set qdf = db.QueryDefs("qryThankYouLettersEnvelopes")
qdf.Parameters(0) = _
Forms!frmThankYouLettersEnvelopes!TYLEBatchNumber
Set rst = qdf.OpenRecordset
'Set rst = CurrentDb.OpenRecordset("QryThankYouLetters")
If rst.RecordCount > 0 Then
DoCmd.RunMacro "TYLEnvelopes"
Application.FollowHyperlink "C:\\My Documents\ThankyouLetterEnvelope.doc"
Else
MsgBox "No records found for this batch number."
End If
rst.Close
qdf.Close
---------------------------------------------------
This works fine when there is only the one parameter, but i have another
query that has a number of parameters where some are left empty "Is Null".
eg. [Forms]![frmGenLetters]![GenBatchNumber] or Like
[Forms]![frmGenLetters]![GenBatchNumber] Is Null
(there is also a "Between" function for date values and "
document.
The document is opened through a module.
-----------------------------------------------------------------------
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Set db = CurrentDb
Set qdf = db.QueryDefs("qryThankYouLettersEnvelopes")
qdf.Parameters(0) = _
Forms!frmThankYouLettersEnvelopes!TYLEBatchNumber
Set rst = qdf.OpenRecordset
'Set rst = CurrentDb.OpenRecordset("QryThankYouLetters")
If rst.RecordCount > 0 Then
DoCmd.RunMacro "TYLEnvelopes"
Application.FollowHyperlink "C:\\My Documents\ThankyouLetterEnvelope.doc"
Else
MsgBox "No records found for this batch number."
End If
rst.Close
qdf.Close
---------------------------------------------------
This works fine when there is only the one parameter, but i have another
query that has a number of parameters where some are left empty "Is Null".
eg. [Forms]![frmGenLetters]![GenBatchNumber] or Like
[Forms]![frmGenLetters]![GenBatchNumber] Is Null
(there is also a "Between" function for date values and "
Code:
" or where
either of these are null)
When I run the similar module to the above I get the error message "Too Few
Parameters Expected (4)"
How can I stop the document from opening if the query is empty.
Thanks
Craig