Loop

Gerrit.B

Board Regular
Joined
Aug 10, 2004
Messages
237
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a access2000 database and in 1 table i have all AirWayBillNumbers.
The query will select the numbers.
After that a macro is mailing the list of numbers.
Still 1 problem to solve.
HowTo create a mail with only 99 numbers folowed by a second mail with the following 99 record till the end of the list.
A module is creating the mail.
:rolleyes: :rolleyes: :rolleyes: :rolleyes: :rolleyes: :rolleyes: :rolleyes: :rolleyes: :rolleyes: :rolleyes:
How to create a loop to seperate the file in mails of max 99 records.

Option Compare Database
Option Explicit

Public cnn As New ADODB.Connection

Function fncMailTrackTraceFile()

Set cnn = CurrentProject.Connection

Dim rstList As New ADODB.Recordset
Dim strMsgTxt As String

rstList.Open "CreateTrackTraceMailFile", cnn, adOpenStatic, adLockReadOnly

strMsgTxt = ""

rstList.MoveFirst
Do Until rstList.EOF
strMsgTxt = strMsgTxt & rstList.Fields(0).Value & Chr$(13)
rstList.MoveNext
Loop

DoCmd.SendObject acSendNoObject, , , "records@mailto.com", , , , strMsgTxt



End Function
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Maybe a change like this:
Code:
Option Compare Database 
Option Explicit 

Public cnn As New ADODB.Connection 

Function fncMailTrackTraceFile() 

Set cnn = CurrentProject.Connection 

Dim rstList As New ADODB.Recordset 
Dim strMsgTxt As String 
Dim x As Integer

rstList.Open "CreateTrackTraceMailFile", cnn, adOpenStatic, adLockReadOnly 

strMsgTxt = "" 
x = 0
rstList.MoveFirst 
Do Until rstList.EOF 
   If x = 99 then
      DoCmd.SendObject acSendNoObject, , , "records@mailto.com", , , , strMsgTxt 
      x=0
      strMsgTxt = ""
   End if
   strMsgTxt = strMsgTxt & rstList.Fields(0).Value & Chr$(13) 
   rstList.MoveNext 
   x = x + 1
Loop 

If strMsgTxt <> "" Then
   DoCmd.SendObject acSendNoObject, , , "records@mailto.com", , , , strMsgTxt 
End If


End Function
Does this help?

Mike.
 
Upvote 0
Works perfect :p

Is it also possible to define the email address of the sender because i do not want to use my default email address.

Thanx
 
Upvote 0

Forum statistics

Threads
1,221,832
Messages
6,162,255
Members
451,757
Latest member
iours

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top