Error 94: Invalid use of null

J

Jesse Aviles

I have the following code assigned to a command button that i intended to
use to copy selected fields of the record to a new record.

Private Sub cmdCloneRecord_Click()
On Error GoTo ErrorHandler
'Create the variables to hold current record values to copy to new record
Dim strCompany As String, strCompanyType As String, strMailingAddress As
String
Dim strTelephone As String, strFax As String, strWebPage As String

strCompany = Company
strCompanyType = CompanyType
strMailingAddress = MailingAddress
strTelephone = Telephone
strFax = Fax
strWebPage = webpage

DoCmd.RunCommand acCmdRecordsGoToNew

Company = strCompany
CompanyType = strCompanyType
MailingAddress = strMailingAddress
Telephone = strTelephone
Fax = strFax
webpage = strWebPage

ErrorHandler:
If Err.Number = 0 Then
Exit Sub
Else
MsgBox "Error#: " & Err.Number & vbCrLf & Err.Description
End If
Exit Sub

End Sub

When I hit the button, I received the subject error. I noticed that this
only happened if some of the field were blank. How can I test for null
values and then only select the fields that are not null? Maybe not Isnull
and select case arguments?

Thank you.
 
K

Ken Pinard

if you can't have nulls then avoid the problem

strCompany = Company & ""

This way the value will not be null

Ken
 

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

Similar Threads

Error 94 Invalid use of Null 4
Error code 3078 1
Nasty Error 94 msg 10
Error: Argument Not Optional 0
Deleting a Form & SubForm Record 1
Invalid use of Null 17
No Error Message wanted 2
Invalid use of Null 7

Top