Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLookUp help needed with Null Value

Status
Not open for further replies.

TriniGal

Programmer
Sep 28, 2005
84
US
Hello,

I have the following code and it works great. I was wondering if it's possible to tweek it a little further to add [R_FOUND], which is a date/time field where it is null.

Code:
Private Sub LOCATION_BeforeUpdate(Cancel As Integer)

Dim varADDRESS As Variant
    
    If Me.NewRecord Then
    
        varADDRESS = DLookup("[ADDRESS]", "LEAKS FOUND", "[ADDRESS] = '" & Me.ADDRESS _
            & "' and [STREET] = '" & Me.LOCATION _
            & "' and [S_COMMUNITY] = '" & Me.S_COMMUNITY & "'")
            
        If Not IsNull(varADDRESS) Then
        
            If MsgBox("This record already exists." & _
                        "Do you want to cancel these changes and go to that record instead?", _
                        vbQuestion + vbYesNo, _
                        "Duplicate Address Found") _
                        = vbYes _
            Then
                Cancel = True
                Me.Undo
                Me.Recordset.FindFirst "[ADDRESS] = '" & varADDRESS & "'"
                bolCheckDuplicate = True
            End If
            
        End If
        
    End If
    
Exit_LOCATION_BeforeUpdate:
    Exit Sub

Err_LOCATION_BeforeUpdate:
    MsgBox Err.Description
    Resume Exit_LOCATION_BeforeUpdate
    
    
End Sub

Basically I want the existing address to show up ONLY if the R_FOUND field is NULL. I've been playing around with the code and have been unsuccessful which leads me to question, if what I'm trying to do even possible?

Thanks in advance for your time.

 

How about?
Code:
varADDRESS = DLookup("[ADDRESS]", "LEAKS FOUND", "[ADDRESS] = '" & Me.ADDRESS _
            & "' and [STREET] = '" & Me.LOCATION _
            & "' and [S_COMMUNITY] = '" & Me.S_COMMUNITY [b][red]_
            & " and IsNull(#" & Me.R_FOUND & "#"[/red][/b])



Randy
 
Randy,

Thank you for your response. I'm getting a syntax error here

Code:
 varADDRESS = DLookup("[ADDRESS]", "LEAKS FOUND", "[ADDRESS] = '" & Me.ADDRESS _
            & "' and [STREET] = '" & Me.LOCATION _
            & "' and [S_COMMUNITY] = '" & Me.S_COMMUNITY _
            & "' and IsNull(#" & Me.R_FOUND & "#"))

Any other suggestions?
 

Yeah,
Change this:
Code:
& "' and IsNull(#" & Me.R_FOUND & "#"))
to this:
Code:
& "' and Trim('" Me.R_FOUND & " ") = "" & "')")


Randy
 
Randy,

Now I'm getting a Compile error: Expected: end of statement

Code:
 varADDRESS = DLookup("[ADDRESS]", "LEAKS FOUND", "[ADDRESS] = '" & Me.ADDRESS _
            & "' And [STREET] = '" & Me.LOCATION _
            & "' And [S_COMMUNITY] = '" & Me.S_COMMUNITY _
            & "' And Trim('" & Me.R_FOUND & " ") = "" & "')")

Where the last closing bracket is highlighted.

Any ideas?
 
sb
Code:
 varADDRESS = DLookup("[ADDRESS]", "LEAKS FOUND", 
             "[ADDRESS] = '" & Me.ADDRESS _
            & "' And [STREET] = '" & Me.LOCATION _
            & "' And [S_COMMUNITY] = '" & Me.S_COMMUNITY _
            & "'  and r_found is null " )

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top