![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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 |
#2
|
|||
|
|||
![]() Please ignore this request. 5 hours later, I finally noticed I had the MailItem delcared as "objMsg" and was referring to it in the code as "obMsg" AAAAAhhhhhhhhhhhh!!!!! "alexcraig" wrote: 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 |
#3
|
|||
|
|||
![]()
If you used "Option Explicit" at the top of all your code modules,
this wouldn't have happened. Or in the VBE, click ToolsOptionsEditor tab, check "Require Variable Declaration" box to add "Option Explicit" automatically to the beginning of every new module. HTH, JP On Jan 6, 1:06*pm, alexcraig wrote: Please ignore this request. 5 hours later, I finally noticed I had the MailItem delcared as "objMsg" and was referring to it in the code as "obMsg" AAAAAhhhhhhhhhhhh!!!!! |
#4
|
|||
|
|||
![]()
JP,
Sounds like a pretty darn good tip! I'll take your advice and maybe save myself a chunk of time in the future. Thanks. "JP" wrote: If you used "Option Explicit" at the top of all your code modules, this wouldn't have happened. Or in the VBE, click ToolsOptionsEditor tab, check "Require Variable Declaration" box to add "Option Explicit" automatically to the beginning of every new module. HTH, JP On Jan 6, 1:06 pm, alexcraig wrote: Please ignore this request. 5 hours later, I finally noticed I had the MailItem delcared as "objMsg" and was referring to it in the code as "obMsg" AAAAAhhhhhhhhhhhh!!!!! |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
CPAO: object reference not set to an instance of an object | Caroline | Outlook - Calandaring | 2 | November 29th 08 04:32 AM |
using outlook object model to add a MailItem to the Sent Items folder | Omatase | Outlook - General Queries | 1 | July 22nd 07 06:29 AM |
Object reference not set to an instance of an object | [email protected] | Outlook - General Queries | 0 | May 17th 07 07:40 AM |
Discarding the changes of mailItem object after saving it to the d | AtulSureka | Outlook - Using Forms | 6 | January 17th 07 02:50 PM |
Help with 'MailItem' object of WordMail Inspector | [email protected] | Add-ins for Outlook | 2 | May 18th 06 07:28 PM |