Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Sending E-mail from Access through SQL (Resolved)

Author  Topic 

scliffe
Starting Member

2 Posts

Posted - 2008-02-19 : 05:22:10
Hi,

I've got a form that will send an e-mail through SQL server with the code below but its breaking at the db.Execute strsend line with a 424 Object Required error. I've got some very similar code on other forms that works fine so I'm thinking I must be overlooking something obvious... Any thoughts? Have I tried to oversimplify or should I be using an alternative to recordsets that I removed.

Private Sub CmdLSSend_Click()

'Define variables
Dim tostr As String
Dim Replacetxt As String
Dim Title As String
Dim strsend As String

'Check all fields completed
If IsNull(txtMessage) Then
MsgBox "Please enter a message"
Exit Sub
End If

If IsNull(cmbRefer) Then
MsgBox "Please select yourself from the list"
Exit Sub
End If

'Define recipient and fix "'" issue
tostr = "address@work.ac.uk"
Replacetxt = Replace(txtMessage, "'", "''")
Title = "Learning Support Referral from " & Trim(Forms!frm_Student_Refer!cmbRefer) & " regarding " & Called

'Send E-mail
strsend = "exec sp_email @attach = '', @number = '" & tostr & "', @comment = '" & Replacetxt & "', @subj = '" & Title & "'"
db.Execute strsend

'Open report for printing
Dim stDoc As String
stDoc = rpt_Student_LSRefer
DoCmd.OpenReport stDoc, acViewNormal

MsgBox "Your form has printed to your default printer and an e-mail has been sent"

'Close Form
DoCmd.Close

End Sub

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2008-02-19 : 10:10:28
object out of scope?
where/how is "db" defined?
Go to Top of Page

scliffe
Starting Member

2 Posts

Posted - 2008-02-20 : 09:09:07
*hangs head in shame!

I oversimplified so much that I didn't define the db... oops.

Just needed to add:

'Define db
Set db = New Connection
db.Provider = "SQLOLEDB"
db.ConnectionString = "user id=******; data source=*******; initial catalog=****; password=********"
db.Open

I knew it would be obvious for someone not staring at it all the time lol Thank you :-)
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2008-02-20 : 09:54:48
bin there, tshirt copyrited!!!
Go to Top of Page
   

- Advertisement -