Invalid use of Null

G

Guest

Hello,

I have a form with a check box, date field and comment field. When the user
fills it out and hits submit, it sends out an email. If I don't click the
check box I get an "Invalid use of null" error. I'm not sure of the proper
way to resolve this.

Here is my code:


Public Sub btnNotice_Click()
On Error GoTo Err_btnNotice_Click

Dim stApproved As Variant
Dim stComments As String
Dim stCompleteDate As String
Dim stStatusReportID As String
Dim stListCode As String
Dim stListName As Variant

If Me.Approved = True Then
stApproved = "yes"
Else
stApproved = "no"
End If
stStatusReportID = Me.StatusReportID
stListCode = Me.Parent!ListCode
stListName = Me.Parent!ListName.Column(1)
stCompleteDate = Me.DateQCComplete
stComments = Me.Description

stText = "Hello," & Chr$(13) & Chr$(13) & _
"An update has been QC'd." & Chr$(13) & Chr$(13) & _
"List Code: " & stListCode & Chr$(13) & Chr$(13) & _
"List Name: " & stListName & Chr$(13) & Chr$(13) & _
"Approved: " & stApproved & Chr$(13) & Chr$(13) & _
"Comments: " & stComments
DoCmd.SendObject , , acFormatRTF, "(e-mail address removed)", , , "QC
complete", stText, 1

DoCmd.Close
' DoCmd.Close.frm003EditListInProcess
Exit_btnNotice_Click:
Exit Sub

Err_btnNotice_Click:
MsgBox err.Description
Resume Exit_btnNotice_Click

End Sub

I'm working in MS Access 2003.

Thank you,
 
J

Jeff Boyce

Marc

Set a breakpoint at the top of your code, and trigger it without the
checkbox. Step through, line by line, checking the values at each step.
Where does the code break?

What is the object that Access is finding a(n improper) Null in?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
B

BruceM

Try setting the default value of the check box to 0 (for False). It would
have helped had you identified the check box field. I assume it is
Me.Approved.
BTW, you could simplify your coding in the message body by using vbCrLf
instead of Chr$(13). In the Sub's declarations:

Dim stCrLf as String
stCrLf = vbCrLf & vbCrLf

Then:

stText = "Hello," & stCrLf & _
"An update has been QC'd." & stCrLf & _
"List Code: " & stListCode & stCrLf & _
etc.
 
M

Matthias Klaey

Marc said:
Hello,

I have a form with a check box, date field and comment field. When the user
fills it out and hits submit, it sends out an email. If I don't click the
check box I get an "Invalid use of null" error. I'm not sure of the proper
way to resolve this.

Here is my code:
[...]

Set the Default Property of the check box to False.

HTH
Matthias Kläy
 
G

Guest

Thanks everyone for the quick replies. I tried
Me.Approved.DefaultValue = 0
and
Me.Approved.DefaultValue = False
but am still getting the error. What am I missing?

and thanks Bruce for the code cleanup tip!
 
G

Guest

Hi Jeff,

I should have tried your idea first. It appears my problem is also in the
"comments" field. It looks like setting the default value of the check box
(approved) solved that problem.

Thanks for your help.
 
B

BruceM

DefaultValue applies only to new records. You would need to change existing
records to have them reflect the value. If you use DefaultValue you must
apply it before the record is first saved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top