Re: Invalid Use of Null

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



Hi Dirk,

Your suggestion worked great. My command button is now working as intended.
Thank you very much.

Chris

"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
    ... Dim DNS As String, DI As Integer ... DNS = DLookup(_ ... Dirk Goldgar, MS Access MVP ...
    (microsoft.public.access.formscoding)
  • Re: Sql Question
    ... on the OnClick of a command button: ... Dim strSQL As String ... Dirk Goldgar, MS Access MVP ...
    (microsoft.public.access.forms)
  • RE: Broken reverse DNS lookup which I cant fix
    ... Change the DNS settings to Standard Primary Zone. ... Change the zone to accept nonsecure and secure dynamic updates. ... On each domain controller, at a command prompt, type the following ... Open Active Directory Users and Computers, click View, Advanced ...
    (microsoft.public.windows.server.sbs)
  • Re: unable to load ONE web site - unknown zone
    ... If you like try setting prompts and see if you at least get a prompt. ... Let's check the DNS because it is the next easiest thing to do ... Open a command window (e.g. Run... ... enter just nslookup ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • RE: Dhcp errors, warnings listed in Event Viewer
    ... There click on your LAN connection and Select Properties, ... Automatically and the DNS. ... CMD.exe click and on the Prompt command type: ... I notice that the alerts show up only then; ...
    (microsoft.public.windowsxp.help_and_support)