Option Compare Database |
|
|
Private Sub btnSave_Click() |
|
Dim strBodyText As String |
Dim strRecipient As String |
Dim strSubject As String |
Dim objDiscrepancy As Object |
'Dim EAddresses As Variant |
Dim x As Integer |
|
Dim objMessage As Object |
Dim objConfig As Object |
Dim objFields As Object |
Dim intIndex As Integer |
|
Dim rstTableName As DAO.Recordset 'Your table |
Dim tblGateKeeper As DAO.Recordset |
Set tblGateKeeper = CurrentDb.OpenRecordset("GateKeeper") |
Dim EmailArray() As String 'Your dynamic array |
Dim intArraySize As Integer 'The size of your array |
Dim iCounter As Integer 'Index of the array |
|
'Open your table |
Set rstTableName = CurrentDb.OpenRecordset("Email_Addresses") |
|
If Not rstTableName.EOF Then |
|
rstTableName.MoveFirst 'Ensure we begin on the first row |
|
'The size of the array should be equal to the number of rows in the table |
intArraySize = rstTableName.RecordCount |
iCounter = 0 |
ReDim EmailArray(intArraySize) 'Need to size the array |
|
Do Until rstTableName.EOF |
|
EmailArray(iCounter) = rstTableName.Fields("Email Address") |
Debug.Print "Item: "; iCounter & " " & EmailArray(iCounter) |
|
iCounter = iCounter + 2 |
rstTableName.MoveNext |
Loop |
|
End If |
|
If IsObject(rstTableName) Then Set rstTableName = Nothing |
|
|
|
|
|
|
|
For x = LBound(EmailArray) To UBound(EmailArray) - 1 |
|
strRecipient = EmailArray(x) |
|
strSubject = "Discrepancy Alert" |
|
strBodyText = "Discrepancy on ID Number: " & Forms!Discrepancy_Kiosk!ID.Value |
|
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. |
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). |
|
Const cdoAnonymous = 0 'Do not authenticate |
Const cdoBasic = 1 'basic (clear-text) authentication |
Const cdoNTLM = 2 'NTLM |
|
'Delivery Status Notifications |
Const cdoDSNDefault = 0 'None |
Const cdoDSNNever = 1 'None |
Const cdoDSNFailure = 2 'Failure |
Const cdoDSNSuccess = 4 'Success |
Const cdoDSNDelay = 8 'Delay |
Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay |
|
Set objMessage = CreateObject("CDO.Message") |
Set objConfig = CreateObject("CDO.Configuration") |
|
'==This section provides the configuration information for the remote SMTP server. |
|
Set objFields = objConfig.Fields |
|
With objFields |
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort |
|
'Name or IP of Remote SMTP Server |
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP-US.CORP.IRCO.COM" '*** ADD SMTP SERVER NAME HERE |
|
'Type of authentication, NONE, Basic (Base64 encoded), NTLM |
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous |
|
'Your UserID on the SMTP server |
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = tblGateKeeper.Fields("UserName") '*** ADD ACCOUNT NAME HERE |
|
'Your password on the SMTP server |
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = tblGateKeeper.Fields("Password") '*** ADD ACCOUNT PASSWORD HERE |
|
'Server port (typically 25) |
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 |
|
'Use SSL for the connection (False or True) |
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False |
|
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server) |
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 |
|
.Update |
End With |
|
With objMessage |
Set .configuration = objConfig |
|
.Subject = strSubject |
.From = "jon.doe@yahoo.com" |
.To = strRecipient |
.TextBody = strBodyText |
|
'If Not (colAttachmentPath Is Nothing) Then |
'For intIndex = 1 To colAttachmentPath.Count |
' .AddAttachment colAttachmentPath(intIndex) |
' Next intIndex |
'End If |
|
.Send |
|
End With |
|
|
|
Set objMessage = Nothing |
Set objConfig = Nothing |
Set objFields = Nothing |
|
Next x |
|
Call MsgBox("Submission Successful!") |
|
DoCmd.GoToRecord , , acNewRec |
|
End Sub |