Results 1 to 3 of 3
  1. #1
    mikevdv is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Jan 2019
    Posts
    1

    Forms With names instead of ID

    Hello and thanks in advance for your help.



    I have a problem

    I have 2 tables, Books and Authors

    Authors contains these rows: AuthorID, Name, gender, Date_of_birth
    Books contain these rows: BookID, AuthorID, Title, Date, Pages,

    I want to make a form to add new Books to my database.
    If i make a normal form, I can input a value for AuthorID, Title, Data, and pages

    There is a problem with this however: If I have a book near me, and want to add it to the database, I need to know the AuthorID of the Author of the book.
    This is a bit not very efficient, because this would mean that I have to look up the AuthorID of the Author of the book in the table 'Authors' first before I can add a new book to the database.


    Is it possible to make a listbox or just a place where I can put in the authors name (in the form) where I can type/select the name of the author, and make it so that access automatically adds the corresponding ID to the form?

    So instead of looking up the ID of the author, I want to put in the Name of the Author.
    And after I put in the name of the author in the form and save it, the table should show the author ID of author.


    To give you an example:
    The table Authors contains the entry: 1, shakespear, male, xxxxx
    When I want to add a book of Shakespear, I want to enter something like the following in the form:

    BookID = 1
    Name = shakespear
    Title = xxx
    Date = yyy
    Pages = zzz

    instead of

    BookID = 1
    AuthorID = 1
    Title = xxx
    Date = yyy
    Pages = zzz

    So when i put in the first form, the updated table (books) should contain his authorID and not his name

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    answer depends: what is AuthorID, an autonumber field? Before going any further, I strongly suggest you correct what will become a problem eventually, and that is your use of reserved words (Name, Date).
    http://allenbrowne.com/AppIssueBadWord.html

    Also, you seem to have a comparable ID field for book, but no comparable field as in author's name. Your tables might need some tweaking.
    Last edited by Micron; 01-31-2019 at 03:36 PM. Reason: correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    mikevdv, this is an extremely easy thing to do and one of the main uses for combo-boxes. Open your existing form in design view, right-click on the AuthorID textbox and change it to combo-box. Then in the properties sheet click on the data tab and on the row source click the three dots to build your SQL (the row source type should stay as Table\Query), add your authors table and select AuthorID and AuthorName. Finally in the columns property enter 2 and set the column widths to 0";3" (you are hidding the authorid column but it remains the bound one).
    Now if you type shakespear in the combo you will see that the books table actually stores 1 (the authorid).
    Cheers,
    Vlad

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

Similar Threads

  1. Replies: 7
    Last Post: 03-21-2018, 04:58 AM
  2. Replies: 2
    Last Post: 01-08-2018, 06:23 PM
  3. Replies: 11
    Last Post: 10-30-2016, 05:39 AM
  4. Replies: 6
    Last Post: 02-28-2015, 01:23 PM
  5. Replies: 5
    Last Post: 04-24-2011, 03:14 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