简体   繁体   中英

dynamically add new text box when users select number higher than 1 on combo-box on access(VBA)

i'm pretty newbie in Access VBA

I'm developing an some access forms for Bussiness car control where users makes requests to use a car.

In the request there will be a combo box where the user have to select how many passangers will be using the car and text boxes to input their name and a phone number.The company can provide Microvans or Vans if the user needs.

My question is how can i add more text boxes according to the number of passengers the user selects? Also i need the text boxes linked to the DB fields for passenger info (I already have all the fields needed in the DB)

I already made some invisible text boxes but as i need many of them the form will become too big fo those user that need only one text box.

Am i doing something too crazy?

When using static userforms, and having textboxes have been set as visible = False , you must ensure that there is enough space for all textboxes to show, should the form require them to turn visible = True .

You can create dynamic userforms; as a greater number of passengers are selected, the form will extend down whilst adding the additional textboxes. It's weighing up whether the development time, and future maintenance time, is worth the form being dynamic in this way. It can get complex and be difficult to maintain in the long run.

I would recommend, instead of having a combobox where they select how many passengers, there is instead 2 buttons '+' and '-', and between these 2 buttons you will have a label which shows the number of passengers. The label increases or decereases, dependant on which button is pressed. This way each time they press to increase passengers, it increases the label and adds an additional textbox. There is an article here which may help if you need ideas on the code this requires: Dynamic Userforms

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM