Recreating some form below after click on ADD button

A

Ali

Hello, I'm having a problem with my form here. I created a bunch of text
boxes in the form design. At the end of the row of the text boxes I want an
ADD button that captures the data I entered and puts them into a record. Then
I want it to create automatically text box row just like the one I had right
underneath right on the bottom of the initial one. Also I want the new row to
keep the some of the initial values so I don't have to keep entering them
over.

Intitial Row: 12 234.5 45 34 23 ADD
New Row: 45 23 ADD

Hope you guys understand what I'm trying to say here.

Thanks.
 
S

Sharkbyte

There are a couple of ways to do this, and I'm certain mine is not the best.
However, you can do something like this:

Make your data-entry text boxes unbound, and when the add button is pressed,
run an Insert statement, to create your record. *Make sure the table you are
saving to is using an autonumber ID field.

Create a subform, based on the max value of the ID field. When the entry
form is first opened, the subform is VISIBLE = NO. When they click Add,
change to VISIBLE = YES, and requery. This should display the previous entry.

Like I said, not as elegant as some solutions, but certainly functional and
not difficult to create.

Good luck.

Sharkbyte
 
A

Ali

What if I have them bound? Is there anyway to make it work?

How would I run the sql statement if unbound? Can you give me the format?

Thanks.
 
J

John Vinson

Hello, I'm having a problem with my form here. I created a bunch of text
boxes in the form design. At the end of the row of the text boxes I want an
ADD button that captures the data I entered and puts them into a record. Then
I want it to create automatically text box row just like the one I had right
underneath right on the bottom of the initial one. Also I want the new row to
keep the some of the initial values so I don't have to keep entering them
over.

Intitial Row: 12 234.5 45 34 23 ADD
New Row: 45 23 ADD

Hope you guys understand what I'm trying to say here.

Thanks.

In addition to the (very flexible, but a fair bit of work) unbound
form Sharkbyte suggests, you can do this with a bound form. You don't
actually *need* an Add button; Access automatically adds the record
when you tab out of the last field in the tab order (unless you have
set the Cycle property of the form to Same Record). You can put on an
Add button if you want the user to be forced to take an extra click -
post back if that's the case.

If not, simply use a Continuous Form (set the form's Default View from
Single Form to Continuous); you may need to drag all the textboxes to
the top of the detail section and snug the bottom of the details
section up, so you can see more than one record at a time.

In the AfterUpdate property of each textbox that you want "carried
over", let's say it's named txtXYZ, click the ... icon, invoke the
Code Builder, and add the following (using your own control name of
course):

Private Sub txtXYZ_AfterUpdate()
Me!txtXYZ.DefaultValue = Chr(34) & Me!txtXYZ & Chr(34)
End Sub

If the user types 3145 into txtXYZ, it will set the (string type!)
DefaultValue property to "3145", and when they type anything on the
new record it will use 3145 as the default for that textbox.

John W. Vinson[MVP]
 
M

Microsoft News Server

John Vinson said:
In addition to the (very flexible, but a fair bit of work) unbound
form Sharkbyte suggests, you can do this with a bound form. You don't
actually *need* an Add button; Access automatically adds the record
when you tab out of the last field in the tab order (unless you have
set the Cycle property of the form to Same Record). You can put on an
Add button if you want the user to be forced to take an extra click -
post back if that's the case.

If not, simply use a Continuous Form (set the form's Default View from
Single Form to Continuous); you may need to drag all the textboxes to
the top of the detail section and snug the bottom of the details
section up, so you can see more than one record at a time.

In the AfterUpdate property of each textbox that you want "carried
over", let's say it's named txtXYZ, click the ... icon, invoke the
Code Builder, and add the following (using your own control name of
course):

Private Sub txtXYZ_AfterUpdate()
Me!txtXYZ.DefaultValue = Chr(34) & Me!txtXYZ & Chr(34)
End Sub

If the user types 3145 into txtXYZ, it will set the (string type!)
DefaultValue property to "3145", and when they type anything on the
new record it will use 3145 as the default for that textbox.

John W. Vinson[MVP]
 
Top