Solved

Invalid Use of Null with a hyperlink field

Posted on 2004-09-07
4
274 Views
Last Modified: 2008-02-20
OK, this one has me about to throw the computer out the window.

I am sending a report from a form using a command button.  The message body will include a link to the document associated with the report - I am pulling that from a hyperlink field called FilePath.  Sometimes that path will be empty, and I can't figure out how to handle it.

Here is the onclick for the command button.

Private Sub Command42_Click()
On Error GoTo Command42_Err
Dim strFilePath As String

strFilePath = Mid(Me.FilePath, 4, Len(Me.FilePath) - 4)


DoCmd.SendObject acSendReport, "rptMemoSend", "SnapshotFormat(*.snp)", , , , "Executive Secretariat Tasking", "Please see the attached document for tasking information related to the following link. <\\pasa27dc01\office shares" & strFilePath & ">", True

Command42_Exit:
    Exit Sub

Command42_Err:
    MsgBox Error$
    Resume Command42_Exit

End Sub

I've tried every freaking combination of If - Else, and If - ElseIf statement I can think of and always get either a data type mismatch, an object required, or, most frequently, an Invalid Use of Null error.

Please - send some advice or a small explosive device this way.
0
Comment
Question by:mattturley
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 12002650
if len(Nz(me.FilePath, "")) > 0 then

   'There's a URL with it...
    DoCmd.SendObject acSendReport, "rptMemoSend", "SnapshotFormat(*.snp)", , , , "Executive Secretariat Tasking", "Please see the attached document for tasking information related to the following link. <\\pasa27dc01\office shares" & strFilePath & ">", True

else
    'There's not a URL with this.
    DoCmd.SendObject acSendReport, "rptMemoSend", "SnapshotFormat(*.snp)", , , , "Executive Secretariat Tasking", "Some other piece of text", True

end if

Hope this helps.
-Jim
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12002653
Well, I'd do something like this:

If IsNull(Me.FilePath) Then
   'The file path is null, do something
Else
   'It isn't empty, send the message.
   strFilePath = Mid(Me.FilePath, 4, Len(Me.FilePath) - 4)
   DoCmd.SendObject acSendReport, "rptMemoSend", "SnapshotFormat(*.snp)", , , , "Executive Secretariat Tasking", "Please see the attached document for tasking information related to the following link. <\\pasa27dc01\office shares" & strFilePath & ">", True
End If
0
 

Author Comment

by:mattturley
ID: 12002758
Thanks Jimhorn...

this is what I ended up using.

If Len(Nz(Me.FilePath, "")) > 0 Then

   'There's a URL with it...
    strFilePath = Mid(Me.FilePath, 4, Len(Me.FilePath) - 4)
    DoCmd.SendObject acSendReport, "rptMemoSend", "SnapshotFormat(*.snp)", , , , "Executive Secretariat Tasking", "Please see the attached document for tasking information related to the following link. <\\pasa27dc01\office shares" & strFilePath & ">", True

Else
    'There's not a URL with this.
    DoCmd.SendObject acSendReport, "rptMemoSend", "SnapshotFormat(*.snp)", , , , "Executive Secretariat Tasking", "Please see the attached document for tasking information.", True

End If

Only difference was that you had not set the strFilePath variable.

Thanks again!

For my (and other's) education... what was most likely causing the Invalid Use of Null?

0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 12006169
Cool beans man.

Null is when there's nothing in a field.  It's different from an empty string "", and it's a pain in the a#@ to handle.  In a field such as URL, where you can't really force the user to enter one if none exists, the best you can do is trap it using the Nz function (Null-to-zero), and handle it accordingly.  

When doing table design, the more fields you set to .Required = True, the less headache this will be, although sometimes it isn't possible, like a person's Alias if they really have none.

Glad I can help.
-Jim

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now