Error 94 Invalid use of Null

I have a button in Access that runs this piece of code:

Private Sub Outlook_Click()
On Error GoTo Add_Err

    'Save record first to be sure required fields are filled.
    DoCmd.RunCommand acCmdSaveRecord

        Dim objOutlook As Outlook.Application
        Dim objAppt As Outlook.AppointmentItem
        Dim objRecurPattern As Outlook.RecurrencePattern

        Set objOutlook = CreateObject("Outlook.Application")
        Set objAppt = objOutlook.CreateItem(olAppointmentItem)

        With objAppt
            .Start = Me!datetobecompleted & " " & Me!StartTime
            .Duration = Me!DurationTime
            .Subject = Me!Device
            .Save
            .Close (olSave)
            End With
            'Release the AppointmentItem object variable.
            Set objAppt = Nothing
 
   'Release the Outlook object variable.
    Set objOutlook = Nothing

       'save the record, display a message.
    DoCmd.RunCommand acCmdSaveRecord
    MsgBox "Appointment Added!"

    Exit Sub

Add_Err:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description
    Exit Sub

End Sub

====

However, when I run it, it comes up with an error saying "Error 94 - Invalid use of Null"

Why am I getting this?????

Many thanks,

Bob...
LVL 10
bob_the_builderAsked:
Who is Participating?
 
livvieConnect With a Mentor Commented:
probably because you are trying to save a record that has a null value in a field that null values aren't allowed.
Debug and check these :
Me!datetobecompleted & " " & Me!StartTime
Me!DurationTime
Me!Device
0
 
Calvin BrineCommented:
What line of code does the error appear on? You will need to disable your error checking to get the access debug dialog.  Let me know where the error occurs.

Cal
0
 
Steve BinkCommented:
Which line is returning that error?  Chances are, it is one of these:

            .Start = Me!datetobecompleted & " " & Me!StartTime
            .Duration = Me!DurationTime
            .Subject = Me!Device

You should make sure that the current record has those fields filled out, or account for the possibility of a NULL value in the assignment like this:

            .Start = Nz(Me!datetobecompleted, "") & " " & Nz(Me!StartTime, "")
            .Duration = Nz(Me!DurationTime, "")
            .Subject = Nz(Me!Device, "")

Repalce the "" with 0 for numeric data.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
dannywarehamCommented:
Take the error trap out.
Where does the code fall over?
I believe it will be in one of these lines@:

            .Start = Me!datetobecompleted & " " & Me!StartTime
            .Duration = Me!DurationTime
            .Subject = Me!Device

Where your control has a null value.

If so, change to:

            .Start = NZ(Me!datetobecompleted,"No Data") & " " & NZ(Me!StartTime,"No Data")
            .Duration = NZ(Me!DurationTime,"No Data")
            .Subject = NZ(Me!Device,"No Data")

If you have a null value, it will put "No Data" in the message.

You could us IsNull(value) to exit the sub from an IF statement, if you wanted.

:-)
0
 
dannywarehamCommented:
routinet - get out of my head
0
 
dannywarehamCommented:
..and you livvie
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Without getting into your code, please do this...

(1)  Place a breakpoint by clicking once on the first actionable line in your code (DoCmd.RunCommand...)
(2)  Run the code, and execution will Stop at that line.  You'll see a yellow bar at that line to signify that's where you are in code execution.
(3)  Hit your {f8} button, and the yellow bar will 'step' from one line to the next.  This is called 'stepping through code'
(4)  Keep hitting your {f8} button until you get your error message again, then post in this question that line.

Hope this helps.
-Jim
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
(sorry boys.. way too slow)
0
 
dannywarehamCommented:
Yours is far moer organised Jim
Ours are a quick and dirty check

:-)
0
 
bob_the_builderAuthor Commented:
Thank you all for your quick response....Basically I were being an idiot and not filling out all the fields correctly....So yes, One of the fields contained a null value..

Many thanks,

Bob...
0
 
Steve BinkCommented:
First, best aye....<sigh>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.