"Invalid use of null"/ Access crash

redpoppy

Registered User.
Local time
Today, 17:22
Joined
Apr 11, 2001
Messages
14
I'm using the following code to send e-mails from a button on a form. Sometimes it works fine, sometimes it stops with the message "invalid use of null" and sometimes it crashes Access! (as per details below). Any help would be much appreciated. Thanks. PS: I'm not proficient in VB, I cobbled this routine together from info on the forum.

Private Sub send_email_Click()
On Error GoTo Err_send_email_Click

Dim stDocName As String
Dim email As String
Dim esubj As String
stDocName = Me.txtmessage
email = Me.E_Mail
esubj = Me.subj
DoCmd.SendObject , , , email, , , esubj, stDocName, True

Exit_send_email_Click:
Exit Sub

Err_send_email_Click:
MsgBox Err.Description
Resume Exit_send_email_Click

End Sub


MSACCESS caused an invalid page fault in
module KERNEL32.DLL at 018f:bff7a138.
Registers:
EAX=02eb8004 CS=018f EIP=bff7a138 EFLGS=00010216
EBX=0ab3ffa8 SS=0197 ESP=00626a00 EBP=00626a40
ECX=57565553 DS=0197 ESI=0ab3f37c FS=5c07
EDX=0b4438bb ES=0197 EDI=02eb8c30 GS=0000
Bytes at CS:EIP:
89 51 08 8b 53 08 8b 43 04 89 42 04 8d 93 0b 10
Stack dump:
00626a40 00000c2c 0ab3f0a8 000002d4 bff7a3a0 0aa40000 0ab3f37c 00000c2c 00000000 0aa4000c 0aa40000 0ab3f0a8 00000040 00000000 0000ab3f 0000ab40
 
When you get the invalid use of null error and hit debug what line of code is having the problem. Its most likely the one with the subject, since not everyone puts a subject. The problem i think your having is your setting string variable to null which is no good. You should check if the objects on the form are Null before assigning a variable to them.

Dim Empty1 As Boolean
Empty1=IsNull(Me.subj)
If Empty1=True
'No Subject
Else
esubj=Me.subj
End If

Empty1=False
Empty1=IsNull(Me.txtmessage)

and so on.

Hope this helps
Greg
 
I am guessing that one of your strings is null. You need to test for nulls and stop the code if one is found.

Private Sub send_email_Click()
On Error GoTo Err_send_email_Click

Dim sDocName As String
Dim sEmail As String
Dim sEsubj As String
sDocName = txtmessage
sEmail = E_Mail
sEsubj = subj

If IsNull (sDocName) or IsNull(sEmail ) or IsNull(sEsubj ) Then
MsgBox "Invalid Null"
Exit Sub
End If

DoCmd.SendObject , , , sEmail, , , sEsubj, sDocName, True

Exit_send_email_Click:
Exit Sub

Err_send_email_Click:
MsgBox Err.Description
Resume Exit_send_email_Click

End Sub
 
Yes, thanks people, you're right. I have a null field where I didn't expect one (email) and your checks pick it up just fine. Thanks for the help.
 

Users who are viewing this thread

Back
Top Bottom