Results 1 to 6 of 6
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    How to specify one table definition in DAO?

    I modified this bit of code found below from another procedure (from another thread):



    Code:
      Dim tdf As DAO.TableDef
      Dim fld As DAO.Field
      For Each tdf In CurrentDb.TableDefs
           For Each fld In tdf.Fields...
              blah, blah
           Next
      Next
    However, in what I'm working on now, I don't want to read all the table definitions.
    How can I specify the name of just one table definition to use?

    Thanks

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    If tdf.Name = "theNameOfTheTable Then ...

    You may not want to 'read' all the defs but you're going to loop over them all. Didn't the code you copied deal with not looping over system tables?
    Last edited by Micron; 11-12-2022 at 03:10 PM. Reason: added question
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Quote Originally Posted by Micron View Post
    If tdf.Name = "theNameOfTheTable Then ...

    You may not want to 'read' all the defs but you're going to loop over them all. Didn't the code you copied deal with not looping over system tables?
    Yes it did, and I presently have what you did in the code, I was just wondering if there is a more direct way, since it's in a routine that gets called over and over again from a higher level.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I'm afraid to ask why it is done over and over. If that's because you're not retaining the returned value, then pass the name to a variable that has the proper scope?
    If it's because you'll need a different name each time then I don't see how you can avoid it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,944
    Quote Originally Posted by twgonder View Post
    I modified this bit of code found below from another procedure (from another thread):

    Code:
      Dim tdf As DAO.TableDef
      Dim fld As DAO.Field
      For Each tdf In CurrentDb.TableDefs
           For Each fld In tdf.Fields...
              blah, blah
           Next
      Next
    However, in what I'm working on now, I don't want to read all the table definitions.
    How can I specify the name of just one table definition to use?

    Thanks
    Use the table name perhaps?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    If you just want one table then something like this

    Code:
        Dim tdf As DAO.TableDef
        Dim fld As DAO.Field
        Dim db As DAO.Database
    
    
        Set db = CurrentDb
        Set tdf = db.TableDefs("tblProducts")
    
    
        For Each fld In tdf.Fields
            Debug.Print fld.Name
        Next
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. first create table in MS access data definition sql view
    By learning_graccess in forum Access
    Replies: 1
    Last Post: 10-14-2011, 06:23 AM
  2. Definition Tables using a Query?
    By AccessMaccess in forum Access
    Replies: 5
    Last Post: 03-22-2011, 10:01 AM
  3. Need help in finding Macro definition
    By sdondeti in forum Access
    Replies: 11
    Last Post: 10-31-2009, 04:52 PM
  4. Replies: 0
    Last Post: 08-13-2008, 03:15 PM
  5. Criteria Definition
    By claing in forum Access
    Replies: 1
    Last Post: 12-19-2005, 07:46 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