Results 1 to 6 of 6
  1. #1
    rmoore is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    Feb 2020
    Posts
    47

    Add fields based on drop down box

    How do I make a drop down box that when the value is selected it will create that many more text fields in the same table and form. The new text fields need to be populated with dates based on a start date with a interval determined in another field.

    Example:
    Drop down box selected 6


    6 date fields named "PaymentDate1, PaymentDate2, PaymentDate3, Etc...." inserted in table or form
    Select date in "PaymentDate1"
    PaymentDate2 thru PaymentDate6 is autofill based on a interval field.


  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    tables are tall and thin, not short and wide like excel

    so I suspect you need code to insert say 6 new records, not create 6 new fields

    something like this in the dropdown box afterupdate event

    Code:
    dim i as integer
    dim sqlstr as string
    
    for i=1 to combo
        sqlstr="INSERT INTO myTable (PaymentDate) VALUES(#" & dateadd("d",me.interval*i,date()) & "#)"
        currentdb.execute sqlstr
    
    next i

  3. #3
    rmoore is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    Feb 2020
    Posts
    47
    I dont want new records. If I select (?) in the combo box, I need that many fields added to the form.

    When I use your code I get
    Compile Error:
    Method or data member not found

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You have suggested multiple repetitive fields fld1,fld2, fld3... which is a red flag indicating you have a table/database design issue.
    These additional "fields" should be records in a related table. In your case it could be Customer or Invoice or other indicating a repayment schedule.. Need more details on your set up, but you definitely would not be following standard database practices with your current approach.
    Good luck.

  5. #5
    rmoore is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    Feb 2020
    Posts
    47
    That makes sense... i will make a payment schedule table. But i still will have a problem with the dates.

    How many date fields needed is determined by number of payments, which changes per record

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    on the basis you are talking about financial loans, very simplistically you would have two tables - name and amount of loan in one and a related table for repayments something like this

    LoanID...LoanName...LoanAmount...LoanDate...NumRep ayments...Frequency
    1...........LoanX.........100...............1/1/2020....4........................Monthly
    2...........LoanY..........300...............1/1/2020....10......................Weekly



    RepaymentID...LoanID..RepaymentDate...RepaymentAmo unt
    1....................1..........1/2/2020............25
    2....................1..........1/3/2020............25
    3....................1..........1/4/2020............25
    4....................1..........1/5/2020............25
    5....................2..........8/1/2020............30
    6....................2..........15/1/2020..........30
    7....................2...........22/1/2020.........30
    etc

    note that technically you do not need the repayment schedule table since it can be calculated from the loan table as and when required - but presumably you would need an actual repayment table to record the amount and date of a repayment

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

Similar Threads

  1. Changing field based on drop down / lookup
    By cballew in forum Forms
    Replies: 2
    Last Post: 06-07-2018, 04:13 PM
  2. Replies: 3
    Last Post: 07-26-2016, 02:12 PM
  3. Calculate Due date based on drop down list
    By Back2Basics in forum Access
    Replies: 2
    Last Post: 04-02-2015, 06:10 AM
  4. Have a drop-down specify which fields appear
    By swavemeisterg in forum Forms
    Replies: 2
    Last Post: 06-06-2012, 01:29 PM
  5. Replies: 3
    Last Post: 12-30-2011, 01:20 PM

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