Improving the AddRow function in a form

R

richardall

I would like to know if the add row function could be improved a little
more.

I would like to add a control icon to a form that would allow the user to
manipulate a table by growing it or shrinking it.

I am currently using this code to add a row if the answer is yes. This
code duplicate the row and fills in the fields to match the existing row.

Sub SpecSheet_AddRow()
response = MsgBox("Add Additional Row?", vbQuestion + vbYesNo)
If response = vbYes Then
Dim rownum As Integer, i As Integer
ActiveDocument.Unprotect
Selection.Tables(1).Rows.Add
rownum = Selection.Tables(1).Rows.Count
For i = 1 To Selection.Tables(1).Columns.Count
ActiveDocument.FormFields.Add Range:=Selection.Tables(1).Cell(rownum,
i).Range, Type:=wdFieldFormTextInput
Next i
Selection.Tables(1).Cell(Selection.Tables(1).Rows.Count,
Selection.Tables(1).Columns.Count).Range.FormFields(1).ExitMacro =
"SpecSheet_addrow"
Selection.Tables(1).Cell(Selection.Tables(1).Rows.Count,
1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub

This code has done well until somebody answered yes but meant to say no.
Because this is a locked form, they couldn’t delete the added row and
ended up sending a quote to a customer with a dead line…

I would like to see if the functions in InfoPath can be recreated in VBA.
For licensing reasons, InfoPath isn’t available to me in this usage.

Here is what I would like to try;

When a user is working in any cell on the row of a table. A control icon
appears next to the beginning of that row. If the cursor is clicked on
the icon, a pull-down menu with a few options appears just below the icon.
These options would be to insert a new row above the current row, insert a
new row below the current row, remove the current row and perhaps clear the
current row.

I would like to make the form better, all suggested will be appreciated.
Please anotate any code as I'm trying to learn VBA and this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top