Results 1 to 5 of 5
  1. #1
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107

    Is it possible to return multiple values with one dlookup statement?

    I would like to get both a customer number and a customer name from my customer file at once. Is this possible with one Dlookup statement? If not, is the recordset the easiest, most efficient way to go? Will continuously opening and closing recordsets in my code slow down my database and/or chew up memory?



    Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The only way would be to return the concatenation of the two values. A recordset is probably as fast or faster than the DLookup() (and almost certainly faster than 2). I would use a recordset since you want 2 values, and it shouldn't have any adverse effects.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    What do you mean by continuously? Like 30 recordsets in one operation? If you want a lot of customer names and numbers in one operation, that's one recordset. As long as you close it, then destroy the variable when done (Set rs = Nothing) you should have no speed or memory issues. As noted, it would be better than repeating two DLookup calls, then concatenating the values before doing whatever with them.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    In my tests the two functions perform at the same speed.
    Code:
    Public Sub test1()
    cTest.StartP
    Debug.Print DLookup("salesorderid", "tblSalesTable", "LineNumber=12") & Space$(1) & cTest.EndP
    End Sub
    Public Sub test2()
    Dim rs
    cTest.StartP
    Set rs = CurrentDb.OpenRecordset("select salesorderid from tblSalesTable where linenumber=12")
    Debug.Print rs!SalesOrderID & Space$(1) & cTest.EndP
    Set rs = Nothing
    End Sub

    my profile class
    Code:
    Option Compare Database
    ' This Class is used to clock and optimize response times at the debug level in the database.
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    
    
    Private Start As Long
    Private Finish As Long
    
    
    Public Sub StartP()
    Start = GetTickCount
    End Sub
    
    
    Public Function EndP() As Double
    Finish = GetTickCount
    EndP = (Finish - Start) / 1000
    End Function
    Changing the 2nd function to Pull * instead of 1 field, is still less 0.1 seconds from 100k records on a database that is stored on a network share.

  5. #5
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    Thank y'all for the information. I will use a recordset.

    Quote Originally Posted by pbaldy View Post
    The only way would be to return the concatenation of the two values. A recordset is probably as fast or faster than the DLookup() (and almost certainly faster than 2). I would use a recordset since you want 2 values, and it shouldn't have any adverse effects.
    Quote Originally Posted by Micron View Post
    What do you mean by continuously? Like 30 recordsets in one operation? If you want a lot of customer names and numbers in one operation, that's one recordset. As long as you close it, then destroy the variable when done (Set rs = Nothing) you should have no speed or memory issues. As noted, it would be better than repeating two DLookup calls, then concatenating the values before doing whatever with them.
    Quote Originally Posted by Perceptus View Post
    In my tests the two functions perform at the same speed.
    Code:
    Public Sub test1()
    cTest.StartP
    Debug.Print DLookup("salesorderid", "tblSalesTable", "LineNumber=12") & Space$(1) & cTest.EndP
    End Sub
    Public Sub test2()
    Dim rs
    cTest.StartP
    Set rs = CurrentDb.OpenRecordset("select salesorderid from tblSalesTable where linenumber=12")
    Debug.Print rs!SalesOrderID & Space$(1) & cTest.EndP
    Set rs = Nothing
    End Sub

    my profile class
    Code:
    Option Compare Database
    ' This Class is used to clock and optimize response times at the debug level in the database.
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    
    
    Private Start As Long
    Private Finish As Long
    
    
    Public Sub StartP()
    Start = GetTickCount
    End Sub
    
    
    Public Function EndP() As Double
    Finish = GetTickCount
    EndP = (Finish - Start) / 1000
    End Function
    Changing the 2nd function to Pull * instead of 1 field, is still less 0.1 seconds from 100k records on a database that is stored on a network share.

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

Similar Threads

  1. iif statement - return a formatted date field
    By tennis2600 in forum Queries
    Replies: 2
    Last Post: 05-30-2015, 09:11 AM
  2. DLookup return value
    By faythe1215 in forum Programming
    Replies: 3
    Last Post: 03-15-2015, 06:18 PM
  3. Query Sql IIf Statement return value
    By ice051505 in forum Queries
    Replies: 10
    Last Post: 03-07-2013, 03:20 PM
  4. Return DLookup result as date?
    By kman42 in forum Access
    Replies: 8
    Last Post: 04-22-2011, 11:35 AM
  5. Dlookup to match two criteria and return value
    By randolphoralph in forum Programming
    Replies: 20
    Last Post: 05-20-2010, 12:27 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