should be easy

binghamw

BingleyW
Local time
Today, 03:02
Joined
Apr 22, 2004
Messages
57
Hello,
I have got the following code on a button which sends an email inserting the current record into the body of the email.
It works fine, however, I would like it to insert ALL the records from the form (there may be multiple records) instead of just the current one on the screen. I would think this is a fairly easy procedure but am not sure exactly how to do this. Any suggestions?



Private Sub Command16_Click()
On Error Resume Next
Dim daBody As String
daBody = ""
daBody = daBody & "UPC: " & Forms!frmMain!UPC.Value & vbCrLf
daBody = daBody & "File Name: " & txtFile.Value & vbCrLf

daBody = daBody & "Date Posted: " & txtDatePost.Value & vbCrLf

daBody = daBody & "Description: " & txtDescription.Value & vbCrLf

daBody = daBody & "Source: " & txtSource.Value & vbCrLf

daBody = daBody & "Accuracy: " & txtAccuracy.Value & vbCrLf

daBody = daBody & "Comments: " & txtComments.Value & vbCrLf

DoCmd.SendObject acSendNoObject, , , "(Wendy Bingham)wendy.bingham@dcr.ca", , , "Update Data Dictionary", daBody

End Sub





Thanks.
 
pardon? I have no idea what that mean....


Please explain.
 
Basically

In VBA, you tell it to cycle all the records in the table, doing what you want for each record.

Code:
Dim rst As New ADODB.Recordset
Dim rstSQL As String
dim daBody as string

rstSQL = "Select * from tblsource" ' Put whatever SQL you want here
    
rst.Open rstSQL, CurrentProject.Connection, adOpenDynamic, adLockPessimistic

    Do While Not rst.EOF
                 daBody = ""
                 daBody = daBody & "UPC: " & rst!UPCFIELD & vbCrLf
                 daBody = daBody & "File Name: " & rst!FileName & vbCrLf
                 daBody = daBody & "Date Posted: " & rst!DatePosted & vbCrLf
                 daBody = daBody & "Description: " & rst!Description & vbCrLf
                 daBody = daBody & "Source: " & txtSource.Value & vbCrLf
                 daBody = daBody & "Accuracy: " & txtAccuracy.Value & vbCrLf
                 daBody = daBody & "Comments: " & txtComments.Value & vbCrLf

                 DoCmd.SendObject acSendNoObject, , , "(Wendy Bingham)wendy.bingham@dcr.ca", , , "Update Data Dictionary", daBody
        rst.MoveNext
    Loop

the rst!Field

rst tells it to pick from your table, and field is the field of the table that has all the records.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom