Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft Access > Criteria works ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 29954 of 31576
Post > Topic >>

Criteria works for FindFirst but not for Dlookup when text contains

by Denise <dh98765@[EMAIL PROTECTED] > Apr 14, 2008 at 09:19 AM

Front end is Access 2002, back end is linked Oracle tables.
My users need to describe things in feet and inches and want to use
the standard ' and " abbrevations.

On a testing form I go to a record with double or single quotes in the
location description and click a button to see if Access can tell me
the ID number and find its way back to the original record.

When the text contains double quotes the FindFirst works but the
Dloookup doesn't.
Why would that be?

This doesn't do any real work, it's just for stepping through in debug
to see what's happening
Private Sub btnFindInClone_Click()
    Dim strCriteria As String
    Dim rst As DAO.Recordset
    Dim strObj As String
    Dim strAct As String
    Dim strLoc As String
    Dim intFY As Integer
    Dim strArea As String

    strObj = Me.OBJECT_NM
    strAct = Me.ACTION_NM
    strArea = Me.METRO_AREA
    intFY = Me.TARGET_FY
    strLoc = Me.LOCATION_DESC


    Set rst = Me.RecordsetClone
' move to a semi-random record in the clone
    rst.MoveLast
    rst.MovePrevious
    rst.MovePrevious
    rst.MovePrevious
    Me.Bookmark = rst.Bookmark
Debug.Print Me.NEED_ID

'           This is the unique constraint of the table
    strCriteria = "OBJECT_NM = '" & strObj & "'" _
        & " and ACTION_NM = '" & strAct & "'" _
        & " and LOCATION_DESC = " & """" & DelimitDblQuotes(strLoc) &
"""" _
        & " and TARGET_FY = " & intFY _
        & " and METRO_AREA = '" & strArea & "'"
Debug.Print strCriteria

' this always returns null if Location Desc contains a double quote,
' but it finds the correct record if Location Desc contains a single
quote or no quotes
    varReturn = DLookup("[NEED_ID]", "FUNDINGNEED", strCriteria)
    If Not IsNull(varReturn) Then
        lngNewNeedID = CLng(varReturn)
    Else
        MsgBox "not found"
    End If

' this always finds the correct record even if single or double quotes
exist in Location Desc
    rst.FindFirst strCriteria
    If rst.NoMatch Then
        MsgBox "not found"
    Else
        Me.Bookmark = rst.Bookmark
    End If

    rst.Close
    Set rst = Nothing

End Sub

Public Function DelimitDblQuotes(strValue As String) As String
    Dim strDblQuote As String

    strDblQuote = """"

'      replace a double quote with 2 double quotes

    DelimitDblQuotes = Replace(Nz(strValue, Space(0)), strDblQuote,
strDblQuote & strDblQuote)


End Function

LOCATION_DESC is defined as VARCHAR2(4000) in Oracle. Access considers
it as Memo data type.

The argument "criteria" is defined almost identically for FindFirst
and Dlookup:
FindFirst criteria: A String used to locate the record. It is like
theWHERE clause in an SQL statement, but without the word WHERE.
Dlookup criteria: An optional string expression used to restrict the
range of data on which the DLookup function is performed. For example,
criteria is often equivalent to the WHERE clause in an SQL expression,
without the word WHERE. If criteria is omitted, the DLookup function
evaluates expr against the entire domain. Any field that is included
in criteria must also be a field in domain; otherwise, the DLookup
function returns a Null.

Why doesn't Dlookup work when FindFirst does?
Thanks
 




 3 Posts in Topic:
Criteria works for FindFirst but not for Dlookup when text conta
Denise <dh98765@[EMAIL  2008-04-14 09:19:57 
Re: Criteria works for FindFirst but not for Dlookup when text c
Rich P <rpng123@[EMAIL  2008-04-14 17:16:27 
Re: Criteria works for FindFirst but not for Dlookup when text
Denise <dh98765@[EMAIL  2008-04-15 05:07:28 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 1:32:08 CST 2008.