473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Run code till end of a record set

Ok I have some code that I want to run on each record in a specific record set. Any ideas on How I can do that? Would it involve the EOF????
Jun 22 '07 #1
8 2797
Ok I have some code that I want to run on each record in a specific record set. Any ideas on How I can do that? Would it involve the EOF????

Yes

Expand|Select|Wrap|Line Numbers
  1. Dim RS As DAO.Recordset
  2.  
  3. Set RS = 
  4. ...
  5.  
  6. Do Until RS.EOF
  7.  
  8. code you want to run on all records
  9.  
  10. Loop
  11.  
I hope that helps.
Jun 22 '07 #2
ADezii
8,834 Expert 8TB
Ok I have some code that I want to run on each record in a specific record set. Any ideas on How I can do that? Would it involve the EOF????
Here is the code for a DAO Recordset, it's a little simpler than ADO:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  2.  
  3. Set MyDB = CurrentDb()
  4. Set MyRS = MyDB.OpenRecordset("tblEmployees", dbOpenDynaset)
  5.  
  6. MyRS.MoveFirst
  7.  
  8. Do While Not MyRS.EOF
  9.   'processing goes here, within the Loop
  10.   Debug.Print MyRS![LastName]    'Print each Last Name in Recordset
  11.     MyRS.MoveNext
  12. Loop
  13.  
  14. MyRS.Close
Jun 22 '07 #3
can I put that code directly into access for a button on click command?
Jun 27 '07 #4
ADezii
8,834 Expert 8TB
can I put that code directly into access for a button on click command?
Yes, you can place the code in any Event Procedure, Function, Sub-Routine, etc.
Jun 27 '07 #5
Yes, you can place the code in any Event Procedure, Function, Sub-Routine, etc.
Ok so say I had a query of a table that gave me a subset of data called query1 for simplicity sake. I am trying to setup an automatic email follow up to these inquiries. I have email code that works but It only sends that one record. the code i have is below: I am sorry to be a pain but it would be so much easier to get this to work through a group of emails rather than use mail merge, just an extra step for people that I am trying to eliminate. If I wrap your code around this will it send the email out to that query set?

Private Sub Command20_Click()

Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatRichText
.To = Me.Email_Address
.Subject = Me.Mess_Subject
.HTMLBody = Me.Mess_Text
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.Add (Me.Mail_Attachment_Path)
End If
'.DeleteAfterSubmit = True 'This would let Outlook send th note without storing it in your sent bin
.Send
End With
'MsgBox MailOutLook.Body
Exit Sub
email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
Resume Error_out
Error_out:
End Sub
Jun 28 '07 #6
ADezii
8,834 Expert 8TB
Ok so say I had a query of a table that gave me a subset of data called query1 for simplicity sake. I am trying to setup an automatic email follow up to these inquiries. I have email code that works but It only sends that one record. the code i have is below: I am sorry to be a pain but it would be so much easier to get this to work through a group of emails rather than use mail merge, just an extra step for people that I am trying to eliminate. If I wrap your code around this will it send the email out to that query set?

Private Sub Command20_Click()

Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatRichText
.To = Me.Email_Address
.Subject = Me.Mess_Subject
.HTMLBody = Me.Mess_Text
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.Add (Me.Mail_Attachment_Path)
End If
'.DeleteAfterSubmit = True 'This would let Outlook send th note without storing it in your sent bin
.Send
End With
'MsgBox MailOutLook.Body
Exit Sub
email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
Resume Error_out
Error_out:
End Sub
kenn, I'm a little confused. Are you trying to send the same E-Mail to multiple Recipients as defined in your Query? Please be more specific and supply additional details such as Posting the SQL of the Query, what Field(s) you are using in the Recordset, and any additional information that comes to mind.
Jun 28 '07 #7
kenn, I'm a little confused. Are you trying to send the same E-Mail to multiple Recipients as defined in your Query? Please be more specific and supply additional details such as Posting the SQL of the Query, what Field(s) you are using in the Recordset, and any additional information that comes to mind.
Ok This might be long winded so please forgive me.

The tool is being used by support rep's that need to send an confirmation email out to all there contacts for the day.

I am trying to get the access tool to automaticly send the emails when they click on there send email button.

The content of the email body and other parts send to and subject are kept in fields in a table. IE Body, EmailAddress, Subject.

The body of the email is generated by choices they make in the tool, whether the dispatch is next day or a 2 hour service call. I have those mechanics worked out.

I have a querry that gives the information required for the emails and I just want to send out all those records in the querry using the information from the fields that are included.

Hope that makes more sense.
Jun 29 '07 #8
ADezii
8,834 Expert 8TB
Ok This might be long winded so please forgive me.

The tool is being used by support rep's that need to send an confirmation email out to all there contacts for the day.

I am trying to get the access tool to automaticly send the emails when they click on there send email button.

The content of the email body and other parts send to and subject are kept in fields in a table. IE Body, EmailAddress, Subject.

The body of the email is generated by choices they make in the tool, whether the dispatch is next day or a 2 hour service call. I have those mechanics worked out.

I have a querry that gives the information required for the emails and I just want to send out all those records in the querry using the information from the fields that are included.

Hope that makes more sense.
Assumptions:
  1. Your Query Name is qryEMail (very original isn't it?). You can change it if you like.
  2. qryEMail contains your specified Fields, namely: [IE Body], [EMailAddress], and [Subject].
  3. I listed only the relevant portion of code, contained within the With..End With construct and the Declarations and Statements necessary for creating the Recordset.
    Expand|Select|Wrap|Line Numbers
    1. Dim MyDB As DAO.Database, MyRS As DAO.Recordset
    2.  
    3. Set MyDB = CurrentDb()
    4. Set MyRS = MyDB.OpenRecordset("qryEMail", dbOpenForwardOnly)
    5.  
    6. With MailOutLook
    7.   .BodyFormat = olFormatRichText
    8.   Do While Not MyRS.EOF
    9.     .To = MyRS![EMailAddress]
    10.     .Subject = MyRS![Subject]
    11.     .HTMLBody = MyRS![IE Body]
    12.        If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
    13.          .Attachments.Add (Me.Mail_Attachment_Path)
    14.        End If
    15.     .Send
    16.       MyRS.MoveNext
    17.   Loop
    18. End With
    19.  
    20. MyRS.Close
  4. That would be the logic as I see it, the details I'll leave for you.
Jun 29 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Greg Fierro | last post by:
I would appreciate any help from anyone with the following: I have an external program (window32 based) that I am executing with the VBA SHELL command. This program produces a text file which I...
5
by: Atara | last post by:
I am trying to convert the following code to VB .Net, I still have some gaps (the lines that are marked with (*)) and also I need an ending condition for the while loop. any help would be...
6
by: Woody Splawn | last post by:
Is there a way in vb.net to delay the firing of certain code till after everything else has run? That is, I have an event with some code in it that needs to run AFTER everything else has run...
1
by: sal21 sal21 | last post by:
I use this code to update a sql database from excel to sql... Now i would want to arange this code to export an Access table into sql databse... Sub ADOExcelToSQLServer() Dim Cn As...
1
by: DIPPU | last post by:
hello sir, m using 4 combo boxes,2 option buttons,button.wen option named single type is clicked data grid must show the data i selected in combo boxes,wen all type option button is clicked then...
0
by: vigneshrao | last post by:
Hi, I have been working on a script that loops through multiple records and sends data (one record per call) to a WS. I am supposed to make a new call for each record before sending the data....
5
by: WascoGTR | last post by:
Hello. This is my code: strWhere = strWhere & "Fpath='" & "programi" & "' And " Fpath record looks like this: N:\PROGRAMI\SISTEMSKI\.... I want to modify the code that will find the...
1
by: dekk | last post by:
Hi, Thanks for viewing this post. I have a subform called 'Time' that captures alot of time activity by day. Two of my fields are 'StartTime' and 'EndTime' I would like to increment the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.