Results 1 to 11 of 11
  1. #1
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59

    VBA Appending a New Field - Can a Listbox Look Up property be added to the Created Field?

    HI folks,



    I've created a proc that creates a table, then creates fields - as per the snippets below. Of course, the CreateField method has just the three arguments shown in the second snippet. But I've never done the following before:

    Is there anyway to modify the new field to have a look up listbox with, in this case, just two values, say "Archibus;Trina"? I don't need list box headers or anything and the user will be allowed to add whatever they want into the field besides the two choices.

    In the second snippet below, tbNew is the variable set for the table, i.e.

    Code:
        Dim db As DAO.Database
        Dim tbNew As DAO.TableDef
    
        Set db = Access.CurrentDb
    
        Set tbNew = db.CreateTableDef("Some New Table Name")

    This is the part with which I am familiar and works perfectly. Other fields have been left out for clarity.

    Just hoping it is possible to add the ???? code:

    Code:
        with tbNew 
            .Fields.Append .CreateField("ArchTrina", dbText, 10)
    
            'Next, add listbox look up for the above field...
            ???????
            
        End With
    
        'Now add the defined table
        db.TableDefs.Append tbNew
    Thanks in advance for any help or what to look for in the MS documentation.

    I hope I've been clear enough. Admonishments are entirely appropriate if I have not.

    Thanks in advance,
    --
    Tim

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Listbox is typically a control on a Form. It gets its data from a table or a list.
    see this for example.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Also, most of us would recommend against a lookup field at the table level:

    http://www.theaccessweb.com/lookupfields.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Thank so much Orange, but I'm talking about adding this:

    Good grief, can't upload an image, hang on, off I go to imgur

    Can't even do that, work computers are locked down so much.

    Anyway, that's not what I'm talking about.

    Take care,
    --
    Tim

  5. #5
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by pbaldy View Post
    Also, most of us would recommend against a lookup field at the table level:

    http://www.theaccessweb.com/lookupfields.htm
    Thank you, Paul, I very much appreciate the advice. Though you are singing to the choir; normally I would too and I personally prefer a look up table myself.

    It really isn't an issue here as I am not developing an application. All I'm doing is creating a table of table fields from a linked Access database where someone imported data from an MS SQL application (Archibus) and added fields of her own which are hoped to be included in a system I am involved with bringing in (SAP). For my own reference, not another user, I want to indicate which fields from her table are from Archibus and which from her. Security won't be an issue. I am not interested in creating forms and other functionality.

    The reason I am automating the creation is because 1) there are a lot of tables involved and 2) I want to be able to redo the set up for similar MS databases and Excel sheets across my department to be able to see what kinds of data different people are using and trying desperately to accommodate it all, somehow, into whatever the SAP system has available.

    FWIW, In Oracle I used to use a varChar2 data type column (field) with Yes and No or True and False as look up values to do the same sort of thing as a Jet/ACE boolean. Different RDBMS of course, but it never caused a problem. When I was working with Jet tables in A2003 and earlier as well as A2007, I would stick to just the linked tables.

    Is the Access Web still being maintained, do you know? It was usually my first stop for a lot of questions and code snippets in the 2000s to abut 2015.

    All the best,
    --
    Tim

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    I'm not sure the lookup field table properties are exposed anywhere, as they effectively are like a "hidden table" access maintains in the background.

    You can list field names from a table really easily in a combo or a list box using the Field List property as the row source?
    So on a form that might help, but can't see how you would apply that in a table creation situation.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by Minty View Post
    I'm not sure the lookup field table properties are exposed anywhere, as they effectively are like a "hidden table" access maintains in the background.

    You can list field names from a table really easily in a combo or a list box using the Field List property as the row source?
    So on a form that might help, but can't see how you would apply that in a table creation situation.
    Thanks Minty. I'll have to be an extra step, then.

    That solves my question!
    --
    Tim

  8. #8
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Hi Tim,

    Please have a look at this thread, I think it could help you with your quest:
    https://stackoverflow.com/questions/...2013-using-sql

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by DittoBird View Post
    Is the Access Web still being maintained, do you know? It was usually my first stop for a lot of questions and code snippets in the 2000s to abut 2015.
    Yes, but the domain changed and the forward may have ended. Try going to:

    http://www.theaccessweb.com/
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by pbaldy View Post
    Yes, but the domain changed and the forward may have ended. Try going to:

    http://www.theaccessweb.com/
    Oh, wonderful, the 1998 - 2017 is reassuring to see as compared to 1998 - 2009.

    Thanks

  11. #11
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by Gicu View Post
    Hi Tim,

    Please have a look at this thread, I think it could help you with your quest:
    https://stackoverflow.com/questions/...2013-using-sql

    Cheers,
    Vlad
    Ah, those properties. I always forget to look there. This is fantastic, Vlad. Thanks so very much.

    Bookmarked for current and future use (with the provisio indicated by Paul, of couyrse!)
    --
    Tim

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

Similar Threads

  1. Replies: 3
    Last Post: 03-11-2020, 11:59 AM
  2. Replies: 9
    Last Post: 05-23-2019, 03:19 AM
  3. Replies: 2
    Last Post: 07-13-2017, 10:44 AM
  4. Replies: 4
    Last Post: 02-03-2016, 09:23 PM
  5. Replies: 3
    Last Post: 12-27-2013, 02:33 PM

Tags for this Thread

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