G
Guest
Dear All
I apologise in advance that this is a long post I am just trying to give you
all the info you will need.
I have posted this before but have been unable to get my code working.
I want to email a copy of a report (converted to PDF) to all the email
addresses resolved from a query,
the parameter comes from the form control Forms![Events1]![EventID] and in
the query it is [em] the query is called Emailteachers
the error I get when running the code is:
Run Time Error 94 Invalid use of NUll: The following line is highlighted
strEmail = .Fields("email")
Here is the code:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim strEmail As String
'Dim sParam As DAO.Parameter
Dim sParam As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("Emailteacher")
sParam = Nz(Forms![Events1]![EventID], "")
qdf.Parameters![Em] = sParam
Set rst = qdf.OpenRecordset
With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If
If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With
EMailAsPDF "Timetable", strEmail, Me.[EventName] & " " & "Cohort " &
Me.[Cohort] & " Timetable", "Enter Your Text Here"
I do hope someone can help, I always seem to fall down when I am using
expressions with null
thanks
Phil
I apologise in advance that this is a long post I am just trying to give you
all the info you will need.
I have posted this before but have been unable to get my code working.
I want to email a copy of a report (converted to PDF) to all the email
addresses resolved from a query,
the parameter comes from the form control Forms![Events1]![EventID] and in
the query it is [em] the query is called Emailteachers
the error I get when running the code is:
Run Time Error 94 Invalid use of NUll: The following line is highlighted
strEmail = .Fields("email")
Here is the code:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim strEmail As String
'Dim sParam As DAO.Parameter
Dim sParam As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("Emailteacher")
sParam = Nz(Forms![Events1]![EventID], "")
qdf.Parameters![Em] = sParam
Set rst = qdf.OpenRecordset
With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("email")
.MoveNext
End If
If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & ", " & .Fields("email")
.MoveNext
Loop
End If
.Close
End With
EMailAsPDF "Timetable", strEmail, Me.[EventName] & " " & "Cohort " &
Me.[Cohort] & " Timetable", "Enter Your Text Here"
I do hope someone can help, I always seem to fall down when I am using
expressions with null
thanks
Phil