Error on missing data

Robster

Registered User.
Local time
Yesterday, 22:08
Joined
Mar 13, 2014
Messages
60
I have the code below which works if there is data in the field "Email" but crashes if the field is empty. How do i get it to ignore if the field is empty?


Dim db As Database
Dim rs As Recordset
Dim emailadd As String


Set db = CurrentDb()
Set rs = db.OpenRecordset("sendexpiredproposals")
emailadd = rs.Fields("Email")

DoCmd.SendObject acReport, "ExpiredProposals", "PDFFormat(*.pdf)", _
emailadd, "", "", "Expired Proposal - " & Date, "This proposal has expired", _
True, ""
 
Something like,
Code:
Dim db As Database
Dim rs As Recordset
Dim emailadd As String


Set db = CurrentDb()
Set rs = db.OpenRecordset("sendexpiredproposals")
emailadd = Nz(rs.Fields("Email"), vbNullString)

If Len(emailadd) <> 0 Then _
    DoCmd.SendObject acReport, "ExpiredProposals", "PDFFormat(*.pdf)", _
                     emailadd, "", "", "Expired Proposal - " & Date, "This proposal has expired", _
                     True, ""
 
still crashes. The highlighted section in the code is
emailadd = Nz(rs.Fields("Email"), vbNullString)
 
Please show the Error Number, Error Description, the SQL of the Query sendexpiredproposals
 
Run-time error '-2147352567 (80020009)
No current Record

sendexpiredproposals is a table. the fields are:
Projectcode, BDLead, Email, ID
 
it's ok. it works.
the record didnt have a corresponding email address.
 

Users who are viewing this thread

Back
Top Bottom