How to Add Fields as Needed on Form
Results 1 to 4 of 4

Thread: How to Add Fields as Needed on Form

  1. #1
    New Member
    Join Date
    May 2010
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default How to Add Fields as Needed on Form

    I'm creating a recipe database, and have a table with 19 fields for ingredients (Ingredient1, Ingredient2, etc). However, not all recipes call for 19 ingredients, and I'd prefer not to have tons of empty fields on the form used to input the recipes. How can I add the fields as needed when the recipe calls for additional fields? Is there a way to use a command button to add fields to a form? Or would some other method work better?

  2. #2
    Board Regular jmacleary's Avatar
    Join Date
    Oct 2015
    Location
    at a desk in the UK
    Posts
    606
    Post Thanks / Like
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to Add Fields as Needed on Form

    Hi there. you could set 18 of the 19 to not visible, and in the change event for each fields make the next one visible. So, your form would start out with 1 visible and 18 hidden, then as each ingredient is entered, the next field will appear. Combine that with making the form 'grow' by altering the height, and it should look pretty good. Make the start height of the form only show the first box (in my case it was 100 as I only had the one textbox on it).

    This code shows you the idea:

    Code:
    Private Sub TextBox1_Change()
    TextBox2.Visible = True
    UserForm1.Height = 130
    End Sub
    Private Sub TextBox2_Change()
    TextBox3.Visible = True
    UserForm1.Height = 160
    End Sub
    and so on for the 19.
    Last edited by jmacleary; Oct 15th, 2018 at 03:44 AM.

  3. #3
    Board Regular
    Join Date
    May 2013
    Posts
    624
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to Add Fields as Needed on Form

    You are approaching this in the wrong way.
    You should have a table tblIngredients and have a record for each ingredient and any other info you want.
    Then it does not matter if it is 2 ingredients or 200.

    HTH
    Office 2007
    Access novice. Sometimes trying to give something back

  4. #4
    Board Regular jmacleary's Avatar
    Join Date
    Oct 2015
    Location
    at a desk in the UK
    Posts
    606
    Post Thanks / Like
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to Add Fields as Needed on Form

    Hi toasterlad

    I misread your details, my answer was based on you using excel not access. As you are indeed using access, I fully agree with welshgasman's observation.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •