"Ronny Sigo" <ro********@sky net.be> wrote in message
news:3f******** **************@ feed0.news.be.e asynet.net...
Hello Arnold,
I used your "more generalised DAO loop", as you suggested. I get no error
messages anymore but ...
This thing serves to automatically generate an email message with the
contents of the tabls in it ...
By each rst.Move.Next, the sBody variable is updated with the old value +
the new one, finally forming the body of the emailmessage.
By using your loop, the email msg displays the correct number of lines
(according to the numer of records in the table - 9 at present (testing)).
The weird thing is that all 9 lines are displaying the values of the first
record, so I get 9 lines exactly the same ..... this beats me .....
Here is the code .... can you see why it does that ?
Private Sub btnStuurMails_C lick()
Forms!frmBekijk Foutmeldingen.R equery
Dim nLast As Long
Dim Email As String, Subject As String, sBody As String, attach As
String Dim cc As String, bcc As String
Subject = "Foutmelding(en )"
Email = "so*****@somepr ovider.be"
sBody = "Beste Karel," & vbCrLf & vbCrLf & _
"De volgende problemen werden mij gemeld. Weet jij hier een oplossing
voor?" & _
vbCrLf & "Met vriendelijke groeten," & vbCrLf & vbCrLf & _
"Steven Leman," & vbCrLf & _
"consulent ICT" & vbCrLf & vbCrLf
'DoCmd.GoToReco rd , , acFirst
tellerke = 0
Dim ronnylogic As Boolean
ronnylogic = False
' Here comes Fletcher's part ...
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM tblFoutmeldinge n"
Set dbs = CurrentDb
Set rst = dbs.OpenRecords et(strSQL)
Do While Not rst.EOF
If [Karel] = True Then
sBody = sBody & "Apparaat: " & Trim([Apparaat]) & "
Beschrijving: " & Trim([Beschrijving]) & _
" Datum: " & [DatumMelding] & " Gebruiker: " &
Trim([Gebruiker]) & vbCrLf & _
Trim([Gebruiker]) & " probeerde dit te herstellen met volgende
handeling(en): " & Trim([OndernomenActie]) & vbCrLf & vbCrLf
[DatumMailKarel] = Date
End If
If [Ronny] = True Then
ronnylogic = True
End If
rst.MoveNext
Loop
If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If
If Not dbs Is Nothing Then
Set dbs = Nothing
End If
' Start Outlook.
' If it is already running, you'll use the same instance...
Dim olApp As Object
'Dim olApp As Outlook.Applica tion
Set olApp = CreateObject("O utlook.Applicat ion")
' Logon. Doesn't hurt if you are already running and logged on...
Dim olNs As Outlook.NameSpa ce
Set olNs = olApp.GetNamesp ace("MAPI")
olNs.Logon
'sFunctie = DLookup("[Functie]", "tblMwerker s", "[Volledigenaam] = '" &
sNaamschrijver & "'")
' Send a message to your new contact.
Dim olMail As Outlook.MailIte m
Set olMail = olApp.CreateIte m(olMailItem)
' Fill out & send message...
'olMail.To = olItem.Email1Ad dress
olMail.To = "so*****@somepr ovider.be"
olMail.Subject = "Foutmelding(en )"
olMail.body = sBody
olMail.Display
'olMail.Send
' Clean up...
Set olNs = Nothing
Set olMail = Nothing
Set olAppt = Nothing
Set olItem = Nothing
Set olApp = Nothing
End Sub
Ronny
Your post has only just appeared on my news server - I don't know why it was
so late. Perhaps you have solved this problem by now, but if not, you could
look at setting a breakpoint at the beginning of the code and use F8 to
step through line by line and see what is going on. You could also help
yourself by reducing the code to a simpler form to make de-bugging easier.
For example, try this version:
While Not rst.EOF
str = str & Nz(rst!Beschrij ving, "") & vbCrLf
rst.MoveNext
Wend
Msgbox str
Does that work? If so, slowly build up to your code. Possible problems:
If [Karel] = True Then ... check this out
[DatumMailKarel] = Date ... this looks like you are trying to edit the
recordset. You can't do that without writing rst.Edit beforehand.
PS My first name is Fletcher
Fletcher