Results 1 to 5 of 5
  1. #1
    forestgump is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    8

    Vlookup & Match on a table in microsoft access

    Hi all,

    Is there a way you can do a vlookup and match type query in access? I need to know how to reference the values in the first column but then all the table field names so the query can find the correct number by looking down and across the table. Is this possible? and if so how would you do it?

    Any help would be much appreciated. If more detail is required please let me know.

    Regards,

    Forestgump

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    you build a query. In the criteria , put what your are searching for and show the fields you wish to see.

  3. #3
    forestgump is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    8
    Hi,

    Thanks for your help, but i don't quite understand your response. I know how to build a query and return the values in fields but in this scenario I want to return the actual field names. i.e. If i had a table called 'Employees' and the fields were 'EmpID', 'FirstName', 'Surname' i would want the query to return 'EmpID', 'FirstName', 'Surname'.

    Regards

    Forestgump

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code is like a box of chocolates....


    Here is a function to return field names from a table. Maybe this will help you:
    Code:
    Sub test()
        Dim fldlst As String
        fldlst = listTableFields("YourTableName")
        MsgBox fldlst
    
       ' Debug.Print fldlst
    End Sub
    
    
    
    Function listTableFields(sTblName As String) As String
    
        Dim db As DAO.Database
        Dim tblfld As DAO.TableDef
        Dim fld As Field
        Dim sListFields As String
        
        Set db = CurrentDb()
        Set tblfld = db.TableDefs(sTblName)
        For Each fld In tblfld.Fields    'loop through all the fields of the table
            sListFields = sListFields & fld.Name & ", "
        Next
    
        If Len(Trim(sListFields)) > 1 Then
            sListFields = Left(sListFields, Len(Trim(sListFields)) - 1)
        End If
        
    'Debug.Print sListFields
    
    
        listTableFields = sListFields
    
    Error_Handler_Exit:
        Set tblfld = Nothing
        Set db = Nothing
        Exit Function
    End Function

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Maybe if you explained why you need this we can better advise on an approach to handle.

    Why would you want a query that displays field names in every record as opposed to the data that is in those fields?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Find an Exact Match in a Access Table column
    By raghavendran in forum Access
    Replies: 4
    Last Post: 10-12-2013, 11:57 AM
  2. Microsoft Access query name arrangement from the table
    By successfulfail in forum Access
    Replies: 3
    Last Post: 10-31-2012, 12:08 PM
  3. Replies: 2
    Last Post: 10-09-2012, 03:20 PM
  4. Replies: 16
    Last Post: 03-13-2012, 03:47 PM
  5. Replies: 1
    Last Post: 09-13-2011, 01:52 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