Results 1 to 5 of 5
  1. #1
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76

    return column number by VBA

    Hi, can anyone tell me how to return number of field by VBA
    Not the FieldCount, but I want to return the single number of field from the table
    example:
    I have a table with the fields like below
    |id | continent | country | province | city | area |......



    I don't know if there is a statement like fieldNumber=2 will represent the column [continent] in the table

    Hope anyone can help me out here, 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,640
    It might help to know what you're actually trying to accomplish. In a recordset, you can use a number to refer to a field. I don't like to do it because it isn't easy to follow later. I think you can also do it with a TableDef.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Can you tell me about how to do it with recordset or TableDef? Just a small sample code would help a lot! Many thanks!

    Quote Originally Posted by pbaldy View Post
    It might help to know what you're actually trying to accomplish. In a recordset, you can use a number to refer to a field. I don't like to do it because it isn't easy to follow later. I think you can also do it with a TableDef.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    This type of thing:

    Code:
      Dim strSql                  As String
      Dim db                      As DAO.Database
      Dim rs                      As DAO.Recordset
    
      Set db = CurrentDb()
    
      strSql = "SELECT * FROM tblNumbers"
      Set rs = db.OpenRecordset(strSql, dbOpenDynaset)
      MsgBox rs.Fields(0)
      Set rs = Nothing
      Set db = Nothing
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    I will try this, Thanks A Lot!

    Quote Originally Posted by pbaldy View Post
    strSql = "SELECT * FROM tblNumbers"
    Set rs = db.OpenRecordset(strSql, dbOpenDynaset)
    MsgBox rs.Fields(0)
    [/CODE]

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

Similar Threads

  1. Replies: 2
    Last Post: 07-27-2012, 08:27 AM
  2. Replies: 0
    Last Post: 03-06-2011, 04:10 AM
  3. Replies: 5
    Last Post: 02-09-2011, 11:22 AM
  4. Replies: 2
    Last Post: 08-09-2010, 08:13 AM
  5. Replies: 1
    Last Post: 04-15-2010, 02:07 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