send report - access visual basic question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Everybody
I have a severe problem with configuring a button that sends a report per
email. The following code does its job:

Private Sub BerichtSendPL_Click()
On Error GoTo Err_BerichtSendPL_Click
Dim stDocName As String, mldg, titel, antwort, subject, cc

cc = LayoutText
subject = "Leiterplatten-Bestellung"
stDocName = "EildienstIntern"
DoCmd.SendObject acReport, stDocName, _
acFormatRTF, Forms![Eildienst Bestellantrag].PLMail, cc, , subject

Exit_BerichtSendPL_CLick:
Exit Sub

Err_BerichtSendPL_Click:

mldg = "Mögliche Fehler:" & Chr(13) & Chr(10) & _
"1) Es ist kein Aussteller gewählt." & Chr(13) & Chr(10) & _
"2) Das Feld 'Projektleiter-Email' ist leer"
titel = "Fehler beim Senden"
antwort = MsgBox(mldg, vbOKOnly, titel)

Resume Exit_BerichtSendPL_CLick

End Sub

BUT the next DOES NOT! When I click on the button I get the errormessage and
after clicking 'OK' I have to shutdown Access with the taskmanager.

Private Sub BerichtSendFirma_Click()
On Error GoTo Err_BerichtSendFirma_Click

Dim stDocName As String
Dim cc As String
Dim mldg, titel, antwort, subject

If Forms![Eildienst Bestellantrag].[Email-Empfänger].Visible = True Then
cc = Forms![Eildienst Bestellantrag].[Email-Empfänger]
Else
cc = ""
End If

subject = "Leiterplatten-Bestellung"
stDocName = "EildienstExtern"
DoCmd.SendObject acReport, stDocName, acFormatRTF, Forms![Eildienst
Bestellantrag].LiefMail, cc, , subject

Exit_BerichtSendFirma_Click:
Exit Sub

Err_BerichtSendFirma_Click:
mldg = "Mögliche Fehler:" & Chr(13) & Chr(10) & _
"1) Es ist kein Aussteller ausgewählt" & Chr(13) & Chr(10) & _
"2) Dem Lieferant ist keine Email-Adresse zugeordnet." & Chr(13) &
Chr(10) & _
"3) 'Musterbau' ist angeklickt und dem Fax-Empfänger ist keine
Email-Adresse zugeordnet"


titel = "Fehler beim Senden"

antwort = MsgBox(mldg, vbOKOnly, titel)
Resume Exit_BerichtSendFirma_Click

End Sub

Can anyone tell me where the error is? I cannot figure it out :(

TIA Walt
 
Does it fail only when Forms![Eildienst Bestellantrag].[Email-Empfänger] is
not visible, or does it fail every time?

If the former, I suspect that passing "" is the culprit.

In your first code snippet, cc is defined as a variant. Assuming that
LayoutText is a control on your form, cc will be Null if LayoutText is
empty. Null and "" are not the same thing!

You could try:

Dim cc As Variant

If Forms![Eildienst Bestellantrag].[Email-Empfänger].Visible = True Then
cc = Forms![Eildienst Bestellantrag].[Email-Empfänger]
Else
cc = Null
End If

or you could change your code to only pass cc when necessary.

subject = "Leiterplatten-Bestellung"
stDocName = "EildienstExtern"
If Forms![Eildienst Bestellantrag].[Email-Empfänger].Visible = True Then
cc = Forms![Eildienst Bestellantrag].[Email-Empfänger]
DoCmd.SendObject acReport, stDocName, acFormatRTF, Forms![Eildienst
Bestellantrag].LiefMail, cc, , subject
Else
DoCmd.SendObject acReport, stDocName, acFormatRTF, Forms![Eildienst
Bestellantrag].LiefMail, , , subject
End If



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)


Walter Becke said:
Hello Everybody
I have a severe problem with configuring a button that sends a report per
email. The following code does its job:

Private Sub BerichtSendPL_Click()
On Error GoTo Err_BerichtSendPL_Click
Dim stDocName As String, mldg, titel, antwort, subject, cc

cc = LayoutText
subject = "Leiterplatten-Bestellung"
stDocName = "EildienstIntern"
DoCmd.SendObject acReport, stDocName, _
acFormatRTF, Forms![Eildienst Bestellantrag].PLMail, cc, , subject

Exit_BerichtSendPL_CLick:
Exit Sub

Err_BerichtSendPL_Click:

mldg = "Mögliche Fehler:" & Chr(13) & Chr(10) & _
"1) Es ist kein Aussteller gewählt." & Chr(13) & Chr(10) & _
"2) Das Feld 'Projektleiter-Email' ist leer"
titel = "Fehler beim Senden"
antwort = MsgBox(mldg, vbOKOnly, titel)

Resume Exit_BerichtSendPL_CLick

End Sub

BUT the next DOES NOT! When I click on the button I get the errormessage and
after clicking 'OK' I have to shutdown Access with the taskmanager.

Private Sub BerichtSendFirma_Click()
On Error GoTo Err_BerichtSendFirma_Click

Dim stDocName As String
Dim cc As String
Dim mldg, titel, antwort, subject

If Forms![Eildienst Bestellantrag].[Email-Empfänger].Visible = True Then
cc = Forms![Eildienst Bestellantrag].[Email-Empfänger]
Else
cc = ""
End If

subject = "Leiterplatten-Bestellung"
stDocName = "EildienstExtern"
DoCmd.SendObject acReport, stDocName, acFormatRTF, Forms![Eildienst
Bestellantrag].LiefMail, cc, , subject

Exit_BerichtSendFirma_Click:
Exit Sub

Err_BerichtSendFirma_Click:
mldg = "Mögliche Fehler:" & Chr(13) & Chr(10) & _
"1) Es ist kein Aussteller ausgewählt" & Chr(13) & Chr(10) & _
"2) Dem Lieferant ist keine Email-Adresse zugeordnet." & Chr(13) &
Chr(10) & _
"3) 'Musterbau' ist angeklickt und dem Fax-Empfänger ist keine
Email-Adresse zugeordnet"


titel = "Fehler beim Senden"

antwort = MsgBox(mldg, vbOKOnly, titel)
Resume Exit_BerichtSendFirma_Click

End Sub

Can anyone tell me where the error is? I cannot figure it out :(

TIA Walt
 
First of all: thank you for replying

I tried both solutions. The first brought no difference, the second worked exactly one time. Now I have the same thing again: I get my error message. I suspect that the access installation is kind of f***ed up. I'll again at home.

Walt

Douglas J. Steele said:
Does it fail only when Forms![Eildienst Bestellantrag].[Email-Empfänger] is
not visible, or does it fail every time?

If the former, I suspect that passing "" is the culprit.

In your first code snippet, cc is defined as a variant. Assuming that
LayoutText is a control on your form, cc will be Null if LayoutText is
empty. Null and "" are not the same thing!

You could try:

Dim cc As Variant

If Forms![Eildienst Bestellantrag].[Email-Empfänger].Visible = True Then
cc = Forms![Eildienst Bestellantrag].[Email-Empfänger]
Else
cc = Null
End If

or you could change your code to only pass cc when necessary.

subject = "Leiterplatten-Bestellung"
stDocName = "EildienstExtern"
If Forms![Eildienst Bestellantrag].[Email-Empfänger].Visible = True Then
cc = Forms![Eildienst Bestellantrag].[Email-Empfänger]
DoCmd.SendObject acReport, stDocName, acFormatRTF, Forms![Eildienst
Bestellantrag].LiefMail, cc, , subject
Else
DoCmd.SendObject acReport, stDocName, acFormatRTF, Forms![Eildienst
Bestellantrag].LiefMail, , , subject
End If



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)


Walter Becke said:
Hello Everybody
I have a severe problem with configuring a button that sends a report per
email. The following code does its job:

Private Sub BerichtSendPL_Click()
On Error GoTo Err_BerichtSendPL_Click
Dim stDocName As String, mldg, titel, antwort, subject, cc

cc = LayoutText
subject = "Leiterplatten-Bestellung"
stDocName = "EildienstIntern"
DoCmd.SendObject acReport, stDocName, _
acFormatRTF, Forms![Eildienst Bestellantrag].PLMail, cc, , subject

Exit_BerichtSendPL_CLick:
Exit Sub

Err_BerichtSendPL_Click:

mldg = "Mögliche Fehler:" & Chr(13) & Chr(10) & _
"1) Es ist kein Aussteller gewählt." & Chr(13) & Chr(10) & _
"2) Das Feld 'Projektleiter-Email' ist leer"
titel = "Fehler beim Senden"
antwort = MsgBox(mldg, vbOKOnly, titel)

Resume Exit_BerichtSendPL_CLick

End Sub

BUT the next DOES NOT! When I click on the button I get the errormessage and
after clicking 'OK' I have to shutdown Access with the taskmanager.

Private Sub BerichtSendFirma_Click()
On Error GoTo Err_BerichtSendFirma_Click

Dim stDocName As String
Dim cc As String
Dim mldg, titel, antwort, subject

If Forms![Eildienst Bestellantrag].[Email-Empfänger].Visible = True Then
cc = Forms![Eildienst Bestellantrag].[Email-Empfänger]
Else
cc = ""
End If

subject = "Leiterplatten-Bestellung"
stDocName = "EildienstExtern"
DoCmd.SendObject acReport, stDocName, acFormatRTF, Forms![Eildienst
Bestellantrag].LiefMail, cc, , subject

Exit_BerichtSendFirma_Click:
Exit Sub

Err_BerichtSendFirma_Click:
mldg = "Mögliche Fehler:" & Chr(13) & Chr(10) & _
"1) Es ist kein Aussteller ausgewählt" & Chr(13) & Chr(10) & _
"2) Dem Lieferant ist keine Email-Adresse zugeordnet." & Chr(13) &
Chr(10) & _
"3) 'Musterbau' ist angeklickt und dem Fax-Empfänger ist keine
Email-Adresse zugeordnet"


titel = "Fehler beim Senden"

antwort = MsgBox(mldg, vbOKOnly, titel)
Resume Exit_BerichtSendFirma_Click

End Sub

Can anyone tell me where the error is? I cannot figure it out :(

TIA Walt
 
Back
Top