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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert additional lines in a template with a button

Status
Not open for further replies.

bfischer414

Technical User
Oct 24, 2002
5
US
I have a form made in ms word 97. My form has a 2 row table in it. I want to be able to click a button to insert additional 2 row tables. How can I do this? I have it setup as a form so it's locked.

Also, would it be possible to have a dialog pop up when the form is opened and have it ask how many of the 2 row tables I would need?

Thanks for any help.

B
 
Hi,

Are you using "I have a form ..." as in FormFields, where you enforce protection?

Are there FormFields in the table, so that when you insert two more rows, it also includes FirlFields in the table cells?

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Yes. My Word document has a table with form fields in it. I would like to be able to have the user click a button to insert another table below the existing table with blank form fields. Or even have the user tell the document how many tables they would need after clicking the button. And then have the document add the appropriate amount of tables.

Does that make sense. Unfortunately I'm not an expert, but would like to automate things a bit on some documents we use daily. And If I could get this document to be flexable with the amount of tables it would help out.

Thanks for your quick reply.
B
 
I actually get this from the net and it works, but it only copies one line of the table and I would need it to copy the table. Also I get an error if I click cancel when the question pops up. Is there anyway to get rid of the error and have it default back to the document as if the button was never clicked or even force the user to answer the question by asking the question again?

Thanks
B

Private Sub CommandButton2_Click()

Dim Count As Integer

'Unprotect Document
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect Password:="test"
End If

Dim InsertRows As Integer
InsertRows = InputBox("Question", _
"InsertRowsTitle", "How many rows would you like to add?")

ActiveDocument.Tables(1).Select
Selection.Tables(1).Rows(2).Select
Selection.Copy
While Count < InsertRows
Selection.Paste
Count = Count + 1
Wend

'Protect Document
If bProtected = False Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="test"
End If

End Sub
 
Ok. Below is what I was able to piece together from the internet and with a little trial and error. Can anyone tell me how I can make it not have "runtime error 13-type mismatch" when I exit the question without giving an answer?



Private Sub CommandButton2_Click()
Dim Count As Integer

'Unprotect Document
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect Password:="test"
End If

Dim InsertRows As Integer
InsertRows = InputBox("Question", _
"InsertRowsTitle", "How many additional lines would you like to add?")

Dim myrange As Range
With ActiveDocument.Tables(1)
Set myrange = .Rows(1).Range
myrange.End = .Rows(2).Range.End
End With

myrange.Select
myrange.Copy

While Count < InsertRows
myrange.Paste
Count = Count + 1
Wend

'Protect Document
If bProtected = False Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="test"
End If

End Sub
 
InsertRows = [!]Val([/!]InputBox("Question", _
"InsertRowsTitle", "How many additional lines would you like to add?")[!])[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top