hey guys,
i downloaded a sample dbase but it seems not to be working right .. i dont know what the problem is .. perhaps you guys can help me ?
here's the sample code for the command button to send the email.
Private Sub cmdSend_Click()
On Error GoTo Err_cmdSend_Click
Dim lngCurrentRow As Integer
Dim strTo As String
Dim strCC As String
Dim strBCC As String
Dim strFrom As String
Dim strReplyTo As String
Dim strAttachment As String
Dim strAttachmentAlias As String
Dim bOK As Boolean
If Me.txtFrom = STR_NULL Or IsNull(Me.txtFrom) Then
MsgBox "You have not entered a valid sender's address.", vbCritical + vbOKOnly, "Error"
Exit Sub
Else
strFrom = Me.txtFrom
End If
If Me.txtReplyTo = STR_NULL Or IsNull(Me.txtReplyTo) Then
strReplyTo = strFrom
Else
strReplyTo = Me.txtReplyTo
End If
If Me.txtSubject = STR_NULL Or IsNull(Me.txtSubject) Then
MsgBox "You have not entered a valid subject.", vbCritical + vbOKOnly, "Error"
Exit Sub
End If
If Me.txtMessageText = STR_NULL Or IsNull(Me.txtMessageText) Then
MsgBox "You have not entered a valid message.", vbCritical + vbOKOnly, "Error"
Exit Sub
End If
For lngCurrentRow = 0 To lstTo.ListCount - 1
If lngCurrentRow = 0 Then
strTo = lstTo.Column(0, lngCurrentRow)
Else
strTo = strTo & ";" & lstTo.Column(0, lngCurrentRow)
End If
Next lngCurrentRow
If strTo = STR_NULL Or IsNull(strTo) Then
MsgBox "You have not entered a valid recipient address.", vbCritical + vbOKOnly, "Error"
Exit Sub
End If
For lngCurrentRow = 0 To lstCC.ListCount - 1
If lngCurrentRow = 0 Then
strCC = lstCC.Column(0, lngCurrentRow)
Else
strCC = strCC & ";" & lstCC.Column(0, lngCurrentRow)
End If
Next lngCurrentRow
For lngCurrentRow = 0 To lstBCC.ListCount - 1
If lngCurrentRow = 0 Then
strBCC = lstBCC.Column(0, lngCurrentRow)
Else
strBCC = strBCC & ";" & lstTo.Column(0, lngCurrentRow)
End If
Next lngCurrentRow
If Me.txtAttachment = STR_NULL Or IsNull(Me.txtAttachment) Then
strAttachment = STR_NULL
Else
strAttachment = Me.txtAttachment
If Me.txtAttachmentAlias = STR_NULL Or IsNull(Me.txtAttachmentAlias) Then
strAttachmentAlias = STR_NULL
Else
strAttachmentAlias = Me.txtAttachmentAlias
End If
End If
bOK = SendMail(strTo, strFrom, Me.txtSubject, Me.txtMessageText, strCC, strBCC, _
strReplyTo, strAttachment, strAttachmentAlias)
Exit_cmdSend_Click:
Exit Sub
Err_cmdSend_Click:
MsgBox err.Description
Resume Exit_cmdSend_Click
End Sub
and here's the sample code for the module.. :
************************************************************
Option Compare Database
Global Const STR_NULL As String = ""
Public Function SendMail(sTo As String, _
sFrom As String, _
sSubject As String, _
sBody As String, _
Optional sCC As String = STR_NULL, _
Optional sBCC As String =STR_NULL, _
Optional sReplyTo As String=STR_NULL, _
Optional sAttachment As String=STR_NULL, _
Optional sAttachmentAlias As String = STR_NULL, _
Optional sPriority As String = "HIGH", _
Optional bHTML As Boolean = False) As Boolean
On Error Resume Next
'CdoBodyFormatHTML = 0
'CdoBodyFormatText = 1
'CdoMailFormatMime = 0
'CdoMailFormatText = 1
Dim oMail As CDONTS.NewMail
' default
SendMail = False
' Create a new mail object
Set oMail = CreateObject("CDONTS.NewMail")
oMail.To = sTo
If sReplyTo = STR_NULL Then sReplyTo = sFrom
oMail.Value("Reply-To") = sReplyTo
oMail.From = sFrom
oMail.Subject = sSubject
sPriority = UCase(sPriority)
If sPriority = "LOW" Then
oMail.Importance = CdoLow
ElseIf sPriority = "HIGH" Then
oMail.Importance = CdoHigh
Else
oMail.Importance = CdoNormal
End If
' Set body format for HTML if needed
If bHTML Then
oMail.BodyFormat = 0
oMail.MailFormat = 0
Else
oMail.BodyFormat = 1
oMail.MailFormat = 1
End If
oMail.Body = sBody
If sAttachment <> STR_NULL Then
If sAttachmentAlias <> STR_NULL Then
oMail.AttachFile sAttachment, sAttachmentAlias
ElseIf bOK The
MsgBox "Message delivered to selected recipients.", vbInformation, "Success"
Else
MsgBox "Error: Message not delivered to selected recipients.", vbCritical, "Failure"
End If
oMail.AttachFile sAttachment
End If
End If
oMail.Send
Set oMail = Nothing
If err Then
SendMail = False
Else
SendMail = True
End If
End Function
************************************************************
Now i get an Error message not delivered to selected recipients. which is from the bOK module
If bOK The
MsgBox "Message delivered to selected recipients.", vbInformation, "Success"
Else
MsgBox "Error: Message not delivered to selected recipients.", vbCritical, "Failure"
End If
my question is .. did i do something wrong ? and if im gettin this error what is the cause of it ? and what can i do to rectify the problem ?
i downloaded a sample dbase but it seems not to be working right .. i dont know what the problem is .. perhaps you guys can help me ?
here's the sample code for the command button to send the email.
Private Sub cmdSend_Click()
On Error GoTo Err_cmdSend_Click
Dim lngCurrentRow As Integer
Dim strTo As String
Dim strCC As String
Dim strBCC As String
Dim strFrom As String
Dim strReplyTo As String
Dim strAttachment As String
Dim strAttachmentAlias As String
Dim bOK As Boolean
If Me.txtFrom = STR_NULL Or IsNull(Me.txtFrom) Then
MsgBox "You have not entered a valid sender's address.", vbCritical + vbOKOnly, "Error"
Exit Sub
Else
strFrom = Me.txtFrom
End If
If Me.txtReplyTo = STR_NULL Or IsNull(Me.txtReplyTo) Then
strReplyTo = strFrom
Else
strReplyTo = Me.txtReplyTo
End If
If Me.txtSubject = STR_NULL Or IsNull(Me.txtSubject) Then
MsgBox "You have not entered a valid subject.", vbCritical + vbOKOnly, "Error"
Exit Sub
End If
If Me.txtMessageText = STR_NULL Or IsNull(Me.txtMessageText) Then
MsgBox "You have not entered a valid message.", vbCritical + vbOKOnly, "Error"
Exit Sub
End If
For lngCurrentRow = 0 To lstTo.ListCount - 1
If lngCurrentRow = 0 Then
strTo = lstTo.Column(0, lngCurrentRow)
Else
strTo = strTo & ";" & lstTo.Column(0, lngCurrentRow)
End If
Next lngCurrentRow
If strTo = STR_NULL Or IsNull(strTo) Then
MsgBox "You have not entered a valid recipient address.", vbCritical + vbOKOnly, "Error"
Exit Sub
End If
For lngCurrentRow = 0 To lstCC.ListCount - 1
If lngCurrentRow = 0 Then
strCC = lstCC.Column(0, lngCurrentRow)
Else
strCC = strCC & ";" & lstCC.Column(0, lngCurrentRow)
End If
Next lngCurrentRow
For lngCurrentRow = 0 To lstBCC.ListCount - 1
If lngCurrentRow = 0 Then
strBCC = lstBCC.Column(0, lngCurrentRow)
Else
strBCC = strBCC & ";" & lstTo.Column(0, lngCurrentRow)
End If
Next lngCurrentRow
If Me.txtAttachment = STR_NULL Or IsNull(Me.txtAttachment) Then
strAttachment = STR_NULL
Else
strAttachment = Me.txtAttachment
If Me.txtAttachmentAlias = STR_NULL Or IsNull(Me.txtAttachmentAlias) Then
strAttachmentAlias = STR_NULL
Else
strAttachmentAlias = Me.txtAttachmentAlias
End If
End If
bOK = SendMail(strTo, strFrom, Me.txtSubject, Me.txtMessageText, strCC, strBCC, _
strReplyTo, strAttachment, strAttachmentAlias)
Exit_cmdSend_Click:
Exit Sub
Err_cmdSend_Click:
MsgBox err.Description
Resume Exit_cmdSend_Click
End Sub
and here's the sample code for the module.. :
************************************************************
Option Compare Database
Global Const STR_NULL As String = ""
Public Function SendMail(sTo As String, _
sFrom As String, _
sSubject As String, _
sBody As String, _
Optional sCC As String = STR_NULL, _
Optional sBCC As String =STR_NULL, _
Optional sReplyTo As String=STR_NULL, _
Optional sAttachment As String=STR_NULL, _
Optional sAttachmentAlias As String = STR_NULL, _
Optional sPriority As String = "HIGH", _
Optional bHTML As Boolean = False) As Boolean
On Error Resume Next
'CdoBodyFormatHTML = 0
'CdoBodyFormatText = 1
'CdoMailFormatMime = 0
'CdoMailFormatText = 1
Dim oMail As CDONTS.NewMail
' default
SendMail = False
' Create a new mail object
Set oMail = CreateObject("CDONTS.NewMail")
oMail.To = sTo
If sReplyTo = STR_NULL Then sReplyTo = sFrom
oMail.Value("Reply-To") = sReplyTo
oMail.From = sFrom
oMail.Subject = sSubject
sPriority = UCase(sPriority)
If sPriority = "LOW" Then
oMail.Importance = CdoLow
ElseIf sPriority = "HIGH" Then
oMail.Importance = CdoHigh
Else
oMail.Importance = CdoNormal
End If
' Set body format for HTML if needed
If bHTML Then
oMail.BodyFormat = 0
oMail.MailFormat = 0
Else
oMail.BodyFormat = 1
oMail.MailFormat = 1
End If
oMail.Body = sBody
If sAttachment <> STR_NULL Then
If sAttachmentAlias <> STR_NULL Then
oMail.AttachFile sAttachment, sAttachmentAlias
ElseIf bOK The
MsgBox "Message delivered to selected recipients.", vbInformation, "Success"
Else
MsgBox "Error: Message not delivered to selected recipients.", vbCritical, "Failure"
End If
oMail.AttachFile sAttachment
End If
End If
oMail.Send
Set oMail = Nothing
If err Then
SendMail = False
Else
SendMail = True
End If
End Function
************************************************************
Now i get an Error message not delivered to selected recipients. which is from the bOK module
If bOK The
MsgBox "Message delivered to selected recipients.", vbInformation, "Success"
Else
MsgBox "Error: Message not delivered to selected recipients.", vbCritical, "Failure"
End If
my question is .. did i do something wrong ? and if im gettin this error what is the cause of it ? and what can i do to rectify the problem ?