Adding a textbox via a button? (1 Viewer)

Darla123

Registered User.
Local time
Yesterday, 23:40
Joined
Jul 29, 2015
Messages
23
Hello. I have a form that has a table as a data source, the table has 5 fields,
Field1, Field2, Field3, Field4, and Field5

Field1 is always visible in the form, but I would like to add an "add" button below it to add the next text box for Field2 for the rest of the fields, and also have a "delete" button to delete the text boxes and data from the form if need be. And then under that another add button for Field3, etc etc. What is the best way to accomplish this?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 04:40
Joined
Feb 19, 2013
Messages
16,607
you can only add or delete controls in design view. Your description of what you require is a bit vague - it sounds like you need a continuous form. Please explain in more detail what you require
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 04:40
Joined
Jul 9, 2003
Messages
16,280
Well, you won't be able to delete them.

You can make them invisible.

You can add and remove objects, but I'm reasonably sure you won't want to do that.

Sent from my SM-G925F using Tapatalk
 

Darla123

Registered User.
Local time
Yesterday, 23:40
Joined
Jul 29, 2015
Messages
23
you can only add or delete controls in design view. Your description of what you require is a bit vague - it sounds like you need a continuous form. Please explain in more detail what you require

Here is a screenshot of what I'm trying to do, I hope this helps, I'm awful at explaining!
 

Attachments

  • 2017-05-22_15-16-26.jpg
    2017-05-22_15-16-26.jpg
    78.7 KB · Views: 38

missinglinq

AWF VIP
Local time
Yesterday, 23:40
Joined
Jun 20, 2003
Messages
6,423
...You can make them invisible...

Uncle has the right idea, here! Presumably you always want Field1 to be Visible, so the 'delete' button code will be different for it than it will for the other buttons.

To set visibility for all buttons, as you move from Record-to-Record, depending on whether or not they have data, you'll need

Code:
Private Sub Form_Current()
 Me.Field1.Visible = True
 Me.Field2.Visible = Not IsNull(Me.Field2)
 Me.Field3.Visible = Not IsNull(Me.Field3)
 Me.Field4.Visible = Not IsNull(Me.Field4)
 Me.Field5.Visible = Not IsNull(Me.Field5)
End Sub

For Field1, you'll need

Code:
Private Sub cmdDeleteField1_Click()
 Me.Field1 = Null
End Sub

For Fields 2-5 you'll need code like this, for each one:

Code:
Private Sub cmdShowField2_Click()
 Field2.Visible = True
End Sub

Code:
Private Sub cmdHideDeleteField2_Click()
 Me.Field2 = Null
 Field2.Visible = False
End Sub
Note that this kind of thing will only work if the Form is in Single View...formatting, such as Visibility applied to a given Control on one Record applies to all Records, in Datasheet and Continuous View Forms.

Linq ;0)>
 

Users who are viewing this thread

Top Bottom