Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid use of null error message

Status
Not open for further replies.

mrbboy

Technical User
Feb 28, 2007
136
US
I have this code for assigning tasks. When I run the code, I get the "Invalid use of null" error message. I looked at all the fields on the form and subform and nothing is null. Why am I getting this error message. Please help.

Dim OutlookApp As New Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Dim AssignedTo As Outlook.Recipient
Dim Email As String

Dim olNS As Outlook.NameSpace

Set OutlookApp = CreateObject("Outlook.Application")
Set olNS = OutlookApp.GetNamespace("MAPI")
olNS.Logon
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)
Email = Replace(Forms![frm_CARReview]![tbl_CARLDReview subform1]!cbo_AssignedTo.Column(1), " ", ".") & "@testamericainc.com"

OutlookTask.Assign
Set AssignedTo = OutlookTask.Recipients.Add(Email)
OutlookTask.Subject = "You have been assigned a task. See CAR Number " & Forms![frm_CARReview]![txt_CARID]
OutlookTask.Body = Forms![frm_CARReview]![tbl_CARLDReview subform1]!txt_ReviewNotes
OutlookTask.DueDate = Forms![frm_CARReview]![tbl_CARLDReview subform1]!txt_PlannedCompletion
OutlookTask.Importance = (olImportanceHigh)
OutlookTask.ReminderSet = True
OutlookTask.Save
OutlookTask.Send
OutlookTask.Display

OutlookApp.Quit
Set OutlookTask = Nothing
 
It would help if you posted where the code breaks. Anywhere you have a value coming from a form, you could use a null to zero function to avoid returning a null and get an idea what the procedure is doing. Ex

= Forms![frm_CARReview]![tbl_CARLDReview subform1]!txt_ReviewNotes

change to
= NZ(Forms![frm_CARReview]![tbl_CARLDReview subform1]!txt_ReviewNotes)

The second parameter of the NZ function is the value that you want returned if there is a null. The default is 0. For example if you want to return the word "null value" instead then

=NZ(Forms![frm_CARReview]![tbl_CARLDReview subform1]!txt_ReviewNotes,"null value")

Another thing I see is the paretheses around OutlookTask.Importance = (olImportanceHigh)
I assume that olImportanceHigh is a constant so this would likely be like writing
OutlookTask.Importance = (2)
Not certain, but I assume this gives an error.
 
How are ya mrbboy . . .

To add to [blue]MajP[/blue] post, I'm particularly caught by your subform referencing which is not correct.

Try this:
Code:
[blue]Dim OutlookApp As New Outlook.Application, OutlookTask As Outlook.TaskItem
Dim AssignedTo As Outlook.Recipient, olNS As Outlook.NameSpace
Dim Email As String, frm As Form, sfrm As Form

Set OutlookApp = CreateObject("Outlook.Application")
Set olNS = OutlookApp.GetNamespace("MAPI")
olNS.Logon
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)
Set [purple][b]frm[/b][/purple] = Forms!frm_CARReview
Set [purple][b]sfrm[/b][/purple] = [purple][b]frm[/b][/purple]![tbl_CARLDReview subform1][purple][b].Form[/b][/purple]


Email = Replace([purple][b]sfrm[/b][/purple]!cbo_AssignedTo.Column(1), " ", ".") & "@testamericainc.com"

OutlookTask.Assign
Set AssignedTo = OutlookTask.Recipients.Add(Email)
OutlookTask.Subject = "You have been assigned a task. See CAR Number " & _
                       [purple][b]frm[/b][/purple]!txt_CARID
OutlookTask.Body = [purple][b]sfrm[/b][/purple]!txt_ReviewNotes
OutlookTask.DueDate = [purple][b]sfrm[/b][/purple]!txt_PlannedCompletion
OutlookTask.Importance = (olImportanceHigh)
OutlookTask.ReminderSet = True
OutlookTask.Save
OutlookTask.Send
OutlookTask.Display

OutlookApp.Quit
Set OutlookTask = Nothing[/blue]
If this fails you'll have to step thru your code to find the culprit . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
How can I assign tasks to more than one person?
 
The problem was with the due date.

Thanks AceMan for correcting some of my mistakes. I really appreciate it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top