DLookup and If/Then

  • Thread starter Thread starter Cheryl
  • Start date Start date
C

Cheryl

Could someone please help me with this one. It retireves
the data from the query properly, and if sbdg is not null
it does what it is supposed to do. If sbdg is null, it
will not output the value of bdg to the form.
Thanks!

Private Sub Account_BeforeUpdate(Cancel As Integer)
Dim bdg As Variant, Sbdg As Variant, bdg2 As Variant


Sbdg = DLookup("[Sub
Building]", "BuildingsQuery", "[SubBuildings.Water Acct #]
='" & Me!Account & "'")
bdg = DLookup
("[Building]", "BuildingsQuery", "[Buildings.Water Acct #]
='" & Me!Account & "'")
bdg2 = DLookup
("[Building]", "BuildingsQuery", "[SubBuildings.Water Acct
#]='" & Me!Account & "'")

If Sbdg = Null Then
Me!Building = bdg
DoCmd.RunMacro "RefreshBuilding"

Else
Me!SubBuilding = Sbdg
Me!Building = bdg2
DoCmd.RunMacro "RefreshBuilding"
DoCmd.RunMacro "RefreshSubBuilding"

End If

End Sub
 
Cheryl said:
Could someone please help me with this one. It retireves
the data from the query properly, and if sbdg is not null
it does what it is supposed to do. If sbdg is null, it
will not output the value of bdg to the form.
Thanks!

Private Sub Account_BeforeUpdate(Cancel As Integer)
Dim bdg As Variant, Sbdg As Variant, bdg2 As Variant


Sbdg = DLookup("[Sub
Building]", "BuildingsQuery", "[SubBuildings.Water Acct #]
='" & Me!Account & "'")
bdg = DLookup
("[Building]", "BuildingsQuery", "[Buildings.Water Acct #]
='" & Me!Account & "'")
bdg2 = DLookup
("[Building]", "BuildingsQuery", "[SubBuildings.Water Acct
#]='" & Me!Account & "'")

If Sbdg = Null Then
Me!Building = bdg
DoCmd.RunMacro "RefreshBuilding"

Else
Me!SubBuilding = Sbdg
Me!Building = bdg2
DoCmd.RunMacro "RefreshBuilding"
DoCmd.RunMacro "RefreshSubBuilding"

End If

End Sub


You can not compare anything to Null. The If statement
should be:

If IsNull(Sbdg) Then
 
Thanks!!!!

-----Original Message-----
Cheryl said:
Could someone please help me with this one. It retireves
the data from the query properly, and if sbdg is not null
it does what it is supposed to do. If sbdg is null, it
will not output the value of bdg to the form.
Thanks!

Private Sub Account_BeforeUpdate(Cancel As Integer)
Dim bdg As Variant, Sbdg As Variant, bdg2 As Variant


Sbdg = DLookup("[Sub
Building]", "BuildingsQuery", "[SubBuildings.Water Acct #]
='" & Me!Account & "'")
bdg = DLookup
("[Building]", "BuildingsQuery", "[Buildings.Water Acct #]
='" & Me!Account & "'")
bdg2 = DLookup
("[Building]", "BuildingsQuery", "[SubBuildings.Water Acct
#]='" & Me!Account & "'")

If Sbdg = Null Then
Me!Building = bdg
DoCmd.RunMacro "RefreshBuilding"

Else
Me!SubBuilding = Sbdg
Me!Building = bdg2
DoCmd.RunMacro "RefreshBuilding"
DoCmd.RunMacro "RefreshSubBuilding"

End If

End Sub


You can not compare anything to Null. The If statement
should be:

If IsNull(Sbdg) Then
 
Back
Top