Re: Invalid Use of Null
- From: Christopher Robin <ChristopherRobin@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 25 Jan 2007 22:21:00 -0800
Hi - thanks for the responses. I will give them a try at work tomorrow.
"Dirk Goldgar" wrote:
"Christopher Robin" <ChristopherRobin@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote.
in message news:1107FED9-DB27-4805-992C-AFA4F8A8B4DA@xxxxxxxxxxxxx
I'm having some problems with some VBA Code. I'm not very familiar
with VBA, so I'm hunting and pecking to get things to work. I have a
button on a form to check whether the values entered by the user
exist in the DB or not. If it exists, then current values from the
DB will be displayed in a text box. If it doesn't exist, I want to
make a new command button visible. This is the part that is always
creating the "Invalid Use of Null" error. Any help would be greatly
appreciated.
Private Sub CheckDomain_Click()
Dim DNS As String, DI As Integer
DNS = DLookup("[TargetDNSName]", "[dbo_TargetDomain]",
"[TargetDNSName]='" & Nz(Me.NewDomainName, " ") & "'")
DI = DLookup("[DomainID]", "[dbo_TargetDomain]", "[TargetDNSName]='"
& Nz(Me.NewDomainName, 0) & "'")
If DNS = " " Then
Me.Submit.Visible = True
Else: Me.DomainIDs = DNS & " DI: " & DI
End If
End Sub
If Either of those DLookups doesn't find a match, it will return Null,
which can't be assigned directly to a String variable (e.g., DNS), or an
Integer variable (e.g., DI). You could get around that in several ways.
Probably the easiest would be to use Variant variables instead of a
String and an Integer:
'----- start of revised code -----
Private Sub CheckDomain_Click()
Dim DNS As Variant ' String or Null
Dim DI As Variant ' Integer or Null
DNS = DLookup( _
"[TargetDNSName]", _
"[dbo_TargetDomain]", _
"[TargetDNSName]='" & _
Nz(Me.NewDomainName, " ") & _
"'")
DI = DLookup( _
"[DomainID]", _
"[dbo_TargetDomain]", _
"[TargetDNSName]='" & _
Nz(Me.NewDomainName, 0) & _
"'")
If IsNull(DNS) Then
Me.Submit.Visible = True
Else
Me.DomainIDs = DNS & " DI: " & DI
End If
End Sub
'----- end of revised code -----
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
- References:
- Re: Invalid Use of Null
- From: Dirk Goldgar
- Re: Invalid Use of Null
- Prev by Date: msgbox
- Next by Date: Re: Detect and trap network connection error on form
- Previous by thread: Re: Invalid Use of Null
- Next by thread: Re: Invalid Use of Null
- Index(es):
Relevant Pages
|