IIf statement problems

Robert C

Registered User.
Local time
Today, 16:08
Joined
Mar 27, 2000
Messages
88
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
 
=IIf(Isnull(Forms!frmClients!sbfClientContact.form!ContactID),"","Attn: " & Forms!frmClients!sbfClientContact.form![ContactFirstName] & " " & Forms!frmClients!sbfClientContact.form![ContactSurname])


???
 
Thank you very much Ken.

It works perfectly now........the phrase "Why didn't I think of that!", springs to mind!

Thanks again, cheers

Rob
 

Users who are viewing this thread

Back
Top Bottom