Results 1 to 2 of 2
  1. #1
    Jack Russel is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2016
    Posts
    7

    Shortening if / dlookup >0 / then dlookup

    I have a number of cases where if a name appears in a particular field, I want to return that name to a variable, and if does not appear then do something else. eg :



    DIM stTransfer as string
    DIM stCoEq as string

    If DLookup("FullName", "Qry_Results", "FullName =" & Chr(34) & stTransfer & Chr(34)) > 0 Then
    stCoEq = DLookup("FullName", "Qry_Results", "FullName =" & Chr(34) & stTransfer & Chr(34))

    else

    make pizza

    It is longwinded and I am sure there is a simpler way !

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You're doing two dlookups which is going to chew time, if you must use a dlookup then I would do something like

    Code:
    dim sFullname
    
    sfullname = dlookup("FullName", "Qry_Results", "Fullname = '" & stTransfer & "'")
    
    if len(sfullname) = 0 then
        'do whatever you're going to do if the fullname is a non zero length
    end if

Please reply to this thread with any new information or opinions.

Similar Threads

  1. DLOOKUP help please
    By goddo2305 in forum Access
    Replies: 5
    Last Post: 05-28-2014, 03:41 AM
  2. Using a DLOOKUP
    By derek7467 in forum Access
    Replies: 9
    Last Post: 02-20-2014, 04:07 PM
  3. You could use (DLookup) instead of (IIf)
    By azhar2006 in forum Queries
    Replies: 7
    Last Post: 02-11-2014, 12:45 PM
  4. Dlookup
    By Bertrand82 in forum Programming
    Replies: 6
    Last Post: 11-23-2012, 01:25 AM
  5. Dlookup
    By pcandeias0 in forum Programming
    Replies: 3
    Last Post: 07-09-2011, 02:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums