Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Template - Can Length of Table Vary With User Input?

Status
Not open for further replies.

b1kerch1ck

Programmer
Nov 22, 2001
29
0
0
US
Hi,

I am creating a template to be used as an expense claim form.

I would like to create a UserForm. I have a good amount of experience coding VBA for Access but it's my first time with Word.

The finished document I envision will contain a table. I want the number of rows in the table to vary with the number of items the user inputs into the UserForm.

Each row will have a cell for date, item description, and dollar amount. The last row will have a calculated control (a label probably) displaying the total of the above dollar amounts.

The problem is this: The number of items a person will be claiming expenses for is a varying factor. It could be one, or it could be a dozen. Can I add a control to the UserForm, ie an 'Add' button, that will add rows to the table until the user is done? Or is there an ActiveX control that looks like a little table, or something like that?

I hope I have posed the question succinctly. This forum has been GREAT and I hope that someone out there will have the answer to this one. I'll keep poking around the help files in the meantime.
 
If you enter data in the rows cell by cell and jump from one cell to the next using TAB, then a tab at the last cell will create a new row.

See what I mean?

_______________________________________

Eman_2005
Technical Communicator
 
Thanks...I know you can do that with a Word document but I don't see how that works with a template.

Would the new rows you get by hitting the tab key have fields in them for the user to enter data into?
 
No they would not have fields. The rows will be empty rows.

Could you describe your UserForm a bit more. I suggest on Initialize, create a table in the document with TEO rows. The first row is for an "item", the second is for your totals.

Start a counter tied to the Add button. If the user is inputing "items" one at a time, then the Add button:

if counter is 0, does NOT add a row
it DOES add the item data to the first row of the table
it increments the counter

if the counter > 0, it DOES add a row. You can do this by moving the selection to the end of the table, and use:

Selection.MoveRight Unit:=wdCell - this is the InTable

equivalent to Tab...if the selection is in the last cell, this makes a new row.

have a Done button ( or a Complete button) that closes off the UserForm. The table should have as many rows as the user input items, plus 1 - the row to be used for the totals.

Gerry
See my Paintings and Sculpture
 
What if you select all the cells in the row when you are in the first cell, stor the selection in a variable, and once a new row is created select the cells of the new row and make the selection = yourVariable
Make sure the selection does not extend beyond the last cell in the row.

_______________________________________

Eman_2005
Technical Communicator
 
Now you're talkin!! :)
I will try this and let you know how it goes.
Am away from work next week so it probably won't be until after that.
Thanks!!!
 
There seems to be (at least to me) a confusion about what are your requirements.

If I understood correctly, you were asking about creating variable tables from a UserForm. The number of rows created was in direct relation to the number of items input by the user from the UserForm.

This is why I asked about the structure and process of the UserForm. Are items selected for input one at a time, or in a bunch.

The process suggested by eman (although it certainly would work) requires:
1. make an input selection from the userform
2. put that item into a row
3. select that row
4. copy the contents to a variable
5. make a new row
6 make that new row content = that variable.

You would have to do that EVERY TIME. If you have 20 items, this operation would have to be done 20 times. As it is using the Selection object, this is going to slow things down. I do not understand the advantage of processing through the table - selecting rows.

You should at least use a Range object, not a Selection.


Gerry
See my Paintings and Sculpture
 
I disagree with you, fumei, regarding how my suggestion could be implemented. But I agree that he did not make it clear how the form will collect user input.

_______________________________________

Eman_2005
Technical Communicator
 
Hi eman_2005! I have seen your other posts, and you know what you are talking about. It is OK to have disagreements. Not a problem with me. But it is also good to figure out what the disagreement is.

So let's have a brief discussion. What, exactly do you not agree with? Using a Range rather than a Selection? If so, where and why? I am always happy to learn something, either new, or better.

Why do you apparently think it is better to dump data from the userForm into a row, then select the same data again, and put it into a variable? Then place it is a different location.

Please explain. I could (VERY possible!) be missing something. If I am, I would much appreciate finding out where I am off track.

thanks!

Gerry
See my Paintings and Sculpture
 
I'd rather wait for b1kerch1ch to further clarify how the form collects user input.
Meanwhile, my disagreement with you is not about using range rather than selection.

The purpose here for me is to help somebody resolve a problem or accomplish a task.
I do not consider this forum a battle field where different IT people compete to display their knowledge or capabilities.

I'm here to learn and to help.


_______________________________________

Eman_2005
Technical Communicator
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top