PC Review


Reply
Thread Tools Rate Thread

Dlookup invalid use of null

 
 
bymarce
Guest
Posts: n/a
 
      12th Feb 2009
Why isn't this Dlookup working? I want this code to look up an email address
in he personel table based on the initials used in an unbound combo box.
When I run it it says "invalid use of null". Thanks.
Marcie

Private Sub Email_Work_Click()

Dim SendTo As String
SendTo = DLookup("Email", "Personel", "Initials = ""Me.fAssignedTo""")
Dim strWhere As String
If Me.FilterOn Then
strWhere = Me.Filter
End If
Debug.Print strWhere

Dim MySubject As String, MyMessage As String
SendTo = Mail
MySubject = Me.MLO
MyMessage = "Please complete the following tests for " & Me.MLO & "."
DoCmd.SendObject acSendReport, "rptWorkAssignments", , SendTo, , ,
MySubject, MyMessage, False

End Sub
 
Reply With Quote
 
 
 
 
Stefan Hoffmann
Guest
Posts: n/a
 
      12th Feb 2009
hi Marcie,

bymarce wrote:
> When I run it it says "invalid use of null". Thanks.


> SendTo = DLookup("Email", "Personel", "Initials = ""Me.fAssignedTo""")

There are two errors, it must be

SendTo = Nz(DLookup("Email", "Personel", _
"Initials = '" & Replace(Me.fAssignedTo, "'", "''") & "'"))

DLookup returns NULL, if doesn't find a match or if the matching field
contains NULL.

The data type String cannot be NULL. You had a mismatch because your
condition was wrong.

Use

MsgBox "Initials = ""Me.fAssignedTo"""

to see what condition you had used.


mfG
--> stefan <--
 
Reply With Quote
 
BeWyched
Guest
Posts: n/a
 
      12th Feb 2009
Probably cos your DLookup statement doesn't make sense. You have incorrect
"'s and, I suggest you use the Nz function to make sure the system doesn't
bomd-out if DLookup can't find a match.

Try changing it to:

SendTo = Nz(DLookup("Email", "Personel", "Initials = '" & Me.fAssignedTo &
"'"), "")

(where '" = exagerated, ' ", and "'" = " ' ")

I would then check SendTo to make sure it doesn't = ""

I also note that later on you change the value of SendTo without using the
DLookup value?

Cheers.

BW

"bymarce" wrote:

> Why isn't this Dlookup working? I want this code to look up an email address
> in he personel table based on the initials used in an unbound combo box.
> When I run it it says "invalid use of null". Thanks.
> Marcie
>
> Private Sub Email_Work_Click()
>
> Dim SendTo As String
> SendTo = DLookup("Email", "Personel", "Initials = ""Me.fAssignedTo""")
> Dim strWhere As String
> If Me.FilterOn Then
> strWhere = Me.Filter
> End If
> Debug.Print strWhere
>
> Dim MySubject As String, MyMessage As String
> SendTo = Mail
> MySubject = Me.MLO
> MyMessage = "Please complete the following tests for " & Me.MLO & "."
> DoCmd.SendObject acSendReport, "rptWorkAssignments", , SendTo, , ,
> MySubject, MyMessage, False
>
> End Sub

 
Reply With Quote
 
David H
Guest
Posts: n/a
 
      12th Feb 2009
I would also add some logic that exits the sub/function if no email is found
and advise the user appropriately.

"Stefan Hoffmann" wrote:

> hi Marcie,
>
> bymarce wrote:
> > When I run it it says "invalid use of null". Thanks.

>
> > SendTo = DLookup("Email", "Personel", "Initials = ""Me.fAssignedTo""")

> There are two errors, it must be
>
> SendTo = Nz(DLookup("Email", "Personel", _
> "Initials = '" & Replace(Me.fAssignedTo, "'", "''") & "'"))
>
> DLookup returns NULL, if doesn't find a match or if the matching field
> contains NULL.
>
> The data type String cannot be NULL. You had a mismatch because your
> condition was wrong.
>
> Use
>
> MsgBox "Initials = ""Me.fAssignedTo"""
>
> to see what condition you had used.
>
>
> mfG
> --> stefan <--
>

 
Reply With Quote
 
bymarce
Guest
Posts: n/a
 
      12th Feb 2009
Thanks for the advise. I plan to add that in.
Marcie

"David H" wrote:

> I would also add some logic that exits the sub/function if no email is found
> and advise the user appropriately.
>
> "Stefan Hoffmann" wrote:
>
> > hi Marcie,
> >
> > bymarce wrote:
> > > When I run it it says "invalid use of null". Thanks.

> >
> > > SendTo = DLookup("Email", "Personel", "Initials = ""Me.fAssignedTo""")

> > There are two errors, it must be
> >
> > SendTo = Nz(DLookup("Email", "Personel", _
> > "Initials = '" & Replace(Me.fAssignedTo, "'", "''") & "'"))
> >
> > DLookup returns NULL, if doesn't find a match or if the matching field
> > contains NULL.
> >
> > The data type String cannot be NULL. You had a mismatch because your
> > condition was wrong.
> >
> > Use
> >
> > MsgBox "Initials = ""Me.fAssignedTo"""
> >
> > to see what condition you had used.
> >
> >
> > mfG
> > --> stefan <--
> >

 
Reply With Quote
 
bymarce
Guest
Posts: n/a
 
      12th Feb 2009
Thanks for the help. I did get the quotes worked out. Now I need to be able
to send this to a group rather than one person. How do I use the forms
filter string to make a recordset to use in the "openrecordset" part of this
code?

Dim SendTo As String
Dim rst As dao.Recordset
Dim db As dao.Database
Set db = CurrentDb()
Set rst = db.OpenRecordset
With rst
If Not .BOF And .EOF Then
Do Until .EOF
SendTo = SendTo & .Fields("Email") & "; "
.MoveNext
Loop
End If
.Close

"bymarce" wrote:

> Why isn't this Dlookup working? I want this code to look up an email address
> in he personel table based on the initials used in an unbound combo box.
> When I run it it says "invalid use of null". Thanks.
> Marcie
>
> Private Sub Email_Work_Click()
>
> Dim SendTo As String
> SendTo = DLookup("Email", "Personel", "Initials = ""Me.fAssignedTo""")
> Dim strWhere As String
> If Me.FilterOn Then
> strWhere = Me.Filter
> End If
> Debug.Print strWhere
>
> Dim MySubject As String, MyMessage As String
> SendTo = Mail
> MySubject = Me.MLO
> MyMessage = "Please complete the following tests for " & Me.MLO & "."
> DoCmd.SendObject acSendReport, "rptWorkAssignments", , SendTo, , ,
> MySubject, MyMessage, False
>
> End Sub

 
Reply With Quote
 
Stefan Hoffmann
Guest
Posts: n/a
 
      12th Feb 2009
h Marcie,

David H wrote:
> I would also add some logic that exits the sub/function if no email is found
> and advise the user appropriately.


Private Sub Email_Work_Click()

Dim SentTo As String

SendTo = Trim(Nz(DLookup("Email", "Personel", _
"Initials = '" & Replace(Me.fAssignedTo, "'", "''") &
"'")), "")

If Len(SendTo) > 0 Then
'Send Email
Else
MsgBox "no reciever."
End IF

End Sub


mfG
--> stefan <--
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DLookUp Invalid Use of NUll iholder Microsoft Access VBA Modules 8 6th Jun 2008 07:06 PM
IIF(ISNULL(...),NULL,...) fires: invalid use of null (?????) =?Utf-8?B?cm9jY28=?= Microsoft Access VBA Modules 3 8th May 2007 12:52 PM
DLookup Invalid Use of Null =?Utf-8?B?UmFuZHkgSGFydHdpY2s=?= Microsoft Access VBA Modules 1 12th Apr 2005 10:06 PM
Dlookup returning invalid use of Null Van T. Dinh Microsoft Access 0 15th Sep 2004 01:19 AM
Re: Dlookup returning invalid use of Null '69 Camaro Microsoft Access 1 14th Sep 2004 10:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:43 PM.