I have a problem with an IIF statement which I am hoping someone can help me solve.
I want to print an envelope – rptC3DEnvelopeDL. The data from this envelope comes from a form – frmClients – which in turn has a subform on it – sbfClientContact – which gets its data from a form – frmContact.
On frmClients I have a button – btnPrintEnvelope – which has the following code behind it:-
Private Sub btnPrintEnvelope_Click()
On Error GoTo Err_btnPrintEnvelope_Click
Dim stDocName As String
stDocName = "rptC3DEnvelopeDL"
If IsNull(Forms!frmClients![sbfClientContact]![ContactID]) Then
DoCmd.OpenReport stDocName, acViewPreview, , "[ClientID]=forms!frmClients![ClientID]"
Else
DoCmd.OpenReport stDocName, acViewPreview, , "[ContactID]=forms!frmClients![sbfClientContact]![ContactID]"
End If
Exit_btnPrintEnvelope_Click:
Exit Sub
Err_btnPrintEnvelope_Click:
MsgBox Err.Description
Resume Exit_btnPrintEnvelope_Click
End Sub
The aim is to print the name and address on the envelope and if there is a contact name for that to appear beneath the last line of the address with the text ”Attn:” preceding the contact names.
IF the contact name fields on the sbfClientContact are null then the text “Attn” should not appear.
On the rptC3DEnvelopeDL I have this statement in the field which should take the contact name:-
=IIf([Isnull](Forms!frmClients!sbfClientContact!ContactID)," ",("Attn: " & [ContactFirstName] & " " & [ContactSurname]))
When I click the button to open the envelope report I get a dialogue box headed
Enter Parameter value
with a field labeled - IsNull
If I click OK at this point the report opens, but there is no contact name after the address – even if there is one on the subform.
Any help would be gratefully received.
Thanks
Rob
I want to print an envelope – rptC3DEnvelopeDL. The data from this envelope comes from a form – frmClients – which in turn has a subform on it – sbfClientContact – which gets its data from a form – frmContact.
On frmClients I have a button – btnPrintEnvelope – which has the following code behind it:-
Private Sub btnPrintEnvelope_Click()
On Error GoTo Err_btnPrintEnvelope_Click
Dim stDocName As String
stDocName = "rptC3DEnvelopeDL"
If IsNull(Forms!frmClients![sbfClientContact]![ContactID]) Then
DoCmd.OpenReport stDocName, acViewPreview, , "[ClientID]=forms!frmClients![ClientID]"
Else
DoCmd.OpenReport stDocName, acViewPreview, , "[ContactID]=forms!frmClients![sbfClientContact]![ContactID]"
End If
Exit_btnPrintEnvelope_Click:
Exit Sub
Err_btnPrintEnvelope_Click:
MsgBox Err.Description
Resume Exit_btnPrintEnvelope_Click
End Sub
The aim is to print the name and address on the envelope and if there is a contact name for that to appear beneath the last line of the address with the text ”Attn:” preceding the contact names.
IF the contact name fields on the sbfClientContact are null then the text “Attn” should not appear.
On the rptC3DEnvelopeDL I have this statement in the field which should take the contact name:-
=IIf([Isnull](Forms!frmClients!sbfClientContact!ContactID)," ",("Attn: " & [ContactFirstName] & " " & [ContactSurname]))
When I click the button to open the envelope report I get a dialogue box headed
Enter Parameter value
with a field labeled - IsNull
If I click OK at this point the report opens, but there is no contact name after the address – even if there is one on the subform.
Any help would be gratefully received.
Thanks
Rob