A
alexcraig
I've solved this problem in the past, but I just cannot remember how.
The below code runs fine until it hits objMsg.Subject = "Test Subject" where
I get an "Object Required" error message.
I guess I am somehow not properly qualifying objMsg.
Please help.
Code:
Dim Source As Variant, Rs1 As ADODB.Recordset
Dim JobOrderNo As String, Srcresult As String, Connect As String, CoID As
String, CoName As String
Dim CoAddress1 As String, CoAddress2 As String, CoCity As String, CoState As
String, CoZip As String
Dim objMsg As MailItem
Dim sInspector As Object
Sub SENDOUTINFO()
'
' Insert Sendout Info
' Macro created 1/5/2008 by Alex Craig
'
' Display Input Box and Get Job Order #
Message = "Enter Job Order #"
Title = "Job Order # Input Box"
JobOrderNo = InputBox(Message, Title)
' Get Job Order Data from Database
Set Rs1 = New ADODB.Recordset
Source = Array("SELECT * FROM tblJobOrders WHERE JobOrderNum = ", "
")
Connect = "Provider=MSDASQL; Driver={SQL Server}; Server=XXXXXXX;
Database=XXX; UID=XX; PWD=XXXXX;"
Source(1) = JobOrderNo
Srcresult = Source(0) & Source(1)
Rs1.Open Srcresult, Connect
Rs1.MoveFirst
CoID = Rs1!CompanyID
Rs1.Close
Set Rs1 = Nothing
' Get Company Data from Database
Set Rs1 = New ADODB.Recordset
Source = Array("SELECT * FROM tblCompanyData WHERE CompanyID = ", "
")
Connect = "Provider=MSDASQL; Driver={SQL Server}; Server=XXXXXXX;
Database=XXX; UID=XX; PWD=XXXXXXXs;"
Source(1) = CoID
Srcresult = Source(0) & Source(1)
Rs1.Open Srcresult, Connect
Rs1.MoveFirst
CoName = Rs1!Name
CoAddress1 = Rs1!Address1
CoAddress2 = Rs1!Address2
CoCity = Rs1!City
CoState = Rs1!StateOrProv
CoZip = Rs1!PostalCode
Rs1.Close
Set Rs1 = Nothing
' Create and populate the email item.
Set objMsg = Application.CreateItem(olMailItem)
obMsg.Subject = "Test Subject"
obMsg.Body = "Test Body"
obMsg.Display
End Sub
The below code runs fine until it hits objMsg.Subject = "Test Subject" where
I get an "Object Required" error message.
I guess I am somehow not properly qualifying objMsg.
Please help.
Code:
Dim Source As Variant, Rs1 As ADODB.Recordset
Dim JobOrderNo As String, Srcresult As String, Connect As String, CoID As
String, CoName As String
Dim CoAddress1 As String, CoAddress2 As String, CoCity As String, CoState As
String, CoZip As String
Dim objMsg As MailItem
Dim sInspector As Object
Sub SENDOUTINFO()
'
' Insert Sendout Info
' Macro created 1/5/2008 by Alex Craig
'
' Display Input Box and Get Job Order #
Message = "Enter Job Order #"
Title = "Job Order # Input Box"
JobOrderNo = InputBox(Message, Title)
' Get Job Order Data from Database
Set Rs1 = New ADODB.Recordset
Source = Array("SELECT * FROM tblJobOrders WHERE JobOrderNum = ", "
")
Connect = "Provider=MSDASQL; Driver={SQL Server}; Server=XXXXXXX;
Database=XXX; UID=XX; PWD=XXXXX;"
Source(1) = JobOrderNo
Srcresult = Source(0) & Source(1)
Rs1.Open Srcresult, Connect
Rs1.MoveFirst
CoID = Rs1!CompanyID
Rs1.Close
Set Rs1 = Nothing
' Get Company Data from Database
Set Rs1 = New ADODB.Recordset
Source = Array("SELECT * FROM tblCompanyData WHERE CompanyID = ", "
")
Connect = "Provider=MSDASQL; Driver={SQL Server}; Server=XXXXXXX;
Database=XXX; UID=XX; PWD=XXXXXXXs;"
Source(1) = CoID
Srcresult = Source(0) & Source(1)
Rs1.Open Srcresult, Connect
Rs1.MoveFirst
CoName = Rs1!Name
CoAddress1 = Rs1!Address1
CoAddress2 = Rs1!Address2
CoCity = Rs1!City
CoState = Rs1!StateOrProv
CoZip = Rs1!PostalCode
Rs1.Close
Set Rs1 = Nothing
' Create and populate the email item.
Set objMsg = Application.CreateItem(olMailItem)
obMsg.Subject = "Test Subject"
obMsg.Body = "Test Body"
obMsg.Display
End Sub