Re: Invalid Use of Null

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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)



.



Relevant Pages

  • Re: Invalid Use of Null
    ... My command button is now working as intended. ... Dim DNS As String, DI As Integer ... Dirk Goldgar, MS Access MVP ...
    (microsoft.public.access.formscoding)
  • Re: Invalid Use of Null
    ... Private Sub CheckDomain_Click ... Dim DNS As String, DI As Integer ... DNS = DLookup(_ ...
    (microsoft.public.access.formscoding)
  • Re: [SLE] (SOLVED!!!)(Revisited) Works in Windoze, NOT in SuSE!?!?!?!?!?!?
    ... dns wasn't working after fresh system install with default modem ... When I changed the init string it began working. ... I'm almost afraid of my modem now. ... Ok, install bind. ...
    (SuSE)
  • Re: Why Five Strings
    ... > DNS wrote: ... >>> That way the B string gets longer so it feels stiffer, ... Prev by Date: ...
    (alt.guitar.bass)
  • Re: Invalid Use of Null
    ... you need to wrap the dLookup results in NZ also... ... so I'm hunting and pecking to get things to work. ... Dim DNS As String, DI As Integer ...
    (microsoft.public.access.formscoding)