Results 1 to 4 of 4
  1. #1
    marianne is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Asia Pacific Region
    Posts
    150

    dlookup versus SQL value search


    to search for values using coding, we can use dlookup to find the values we need, like:

    x=dlookup("fieldname","tablename","criteria=y")

    so there we get the value for x.

    how can I use SQL to get the value of x in a table?

    thanks.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You would need to use a RecordSet and a SELECT statement Marianne.

  3. #3
    marianne is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Asia Pacific Region
    Posts
    150
    can you give me an example code RG?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It would look something like:
    Code:
    Public Function Fooo() As Variant
       Dim MyRs As DAO.Recordset, MySQL As String
       MySQL = "SELECT fieldname " & _
               "FROM tablename " & _
               "WHERE criteria = y"
       Set MyRs = CurrentDb().OpenRecordset(MySQL, dbOpenDynaset)
       Fooo = MyRs![fieldname]
       MyRs.Close
       Set MyRs = Nothing
    End Function
    ...which is basically what DLookup does anyway.

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

Similar Threads

  1. Dlookup
    By janjan_376 in forum Access
    Replies: 20
    Last Post: 07-07-2009, 07:40 AM
  2. Dlookup question
    By nkenney in forum Forms
    Replies: 3
    Last Post: 07-01-2009, 06:36 PM
  3. # added to string with Dlookup
    By normever in forum Programming
    Replies: 1
    Last Post: 02-27-2009, 10:52 AM
  4. Need Help for Dlookup function
    By wasim_sono in forum Programming
    Replies: 5
    Last Post: 01-04-2006, 08:18 AM

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