I’ve created a command button Add Land.
Workflow:
Users click button ‘Add Land’, the result is a building blocks inserted to enter additional land title details.
The building blocks are designed as a table cell.
On the top right hand corner I’ve added a checkbox.
When users click the X, the results are table cell deleted.
A few blockages and questions:
The checkbox Run Macro on Exit - how can I set this. – screen capture in green highlight
As an alternative I've created a command button, added a picture of X – screen capture in yellow highlight
Is the best & easier method a checkbox, or command button.
When the building blocks inserted, Word automatically names the checkbox and /or command button.
For example the original command buttons name is cmdDeleteLand
Insert a building block, the new command button name is cmdDeleteLand1
Insert a 2nd building block, the new command button name is cmdDeleteLand2
What’s the best way to capture the events of the current command button, as I wont know the exact command button name
For example the current code is this:
Private Sub cmdDeleteLand_Click()
Selection.SelectCell
Selection.Cells.Delete ShiftCells:=wdDeleteCellsShiftLeft
End Sub
Private Sub cmdDeleteLand1_Click()
Selection.SelectCell
Selection.Cells.Delete ShiftCells:=wdDeleteCellsShiftLeft
End Sub
TIA dd
Word 2007 - dynamic word forms checkbox or command button
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Word 2007 - dynamic word forms checkbox or command button
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78478
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Word 2007 - dynamic word forms checkbox or command butt
If you have assigned a Macro on Exit to the check box in the building block, it will be assigned to each instance that the user inserts into the document.
If you want to assign a macro programmatically, you can do something like
If you want to assign a macro programmatically, you can do something like
Code: Select all
With Selection.FormFields(1)
.ExitMacro = "Test"
End With
Best wishes,
Hans
Hans
-
- Microsoft MVP
- Posts: 1318
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: Word 2007 - dynamic word forms checkbox or command butt
Some thoughts:
Instead of a check box (which requires the user to click and then exit to fire the exit macro) or an ActiveX command button (which requires a unique name and a unique code procedure for each one), it's better to place a MacroButton field in the building block. The display text of the field can be a check box from the Wingdings font, or text like "Remove cell", and it can be given a border and background shade so it looks like a button.
Let each MacroButton field (or check box, if you want to stay with those) call the same macro -- don't try to change procedure names on the fly! Inside that one macro, you can get the cell that contains the item that was clicked, and delete it:
Dim oCell as Word.Cell
Set oCell = Selection.Cells(1)
oCell.Delete
The attached document demonstrates the technique.
The default for a MacroButton field is to require a double-click to execute the macro, but an AutoOpen macro can set Options.ButtonFieldClicks = 1 to change that. (You might also want an AutoClose macro that sets it back to 2.)
Instead of a check box (which requires the user to click and then exit to fire the exit macro) or an ActiveX command button (which requires a unique name and a unique code procedure for each one), it's better to place a MacroButton field in the building block. The display text of the field can be a check box from the Wingdings font, or text like "Remove cell", and it can be given a border and background shade so it looks like a button.
Let each MacroButton field (or check box, if you want to stay with those) call the same macro -- don't try to change procedure names on the fly! Inside that one macro, you can get the cell that contains the item that was clicked, and delete it:
Dim oCell as Word.Cell
Set oCell = Selection.Cells(1)
oCell.Delete
The attached document demonstrates the technique.
The default for a MacroButton field is to require a double-click to execute the macro, but an AutoOpen macro can set Options.ButtonFieldClicks = 1 to change that. (You might also want an AutoClose macro that sets it back to 2.)
You do not have the required permissions to view the files attached to this post.
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: Word 2007 - dynamic word forms checkbox or command butt
Thank you Hans and Jay
I looked at both suggestions and both solutions worked.
I used Jays method as it was easier and simpler to implement.
Many thanks again
dd
I looked at both suggestions and both solutions worked.
I used Jays method as it was easier and simpler to implement.
Many thanks again
dd
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: Word 2007 - dynamic word forms checkbox or command butt
Hi again,
Using Option buttons I’ve hit the same blockage. see screen capture
The first table option buttons work, due to code running on unique option button names. eg
optIndividual
optCorporation
I create a building block based on Mortgagee table, that includes several option button groups.
When the building blocks inserted into the document, the result is default names are given to the new option button eg
optIndividual2
optCorporation2
optIndividual21
optCorporation21
I wont know the option button names, or how manys option buttons are inserted.
Is there a standard click event for option buttons, that I can capture to run on any option button selected.
Is it possible to do something similar with the checkbox macrofield, and run on option buttons
TIA dd
Using Option buttons I’ve hit the same blockage. see screen capture
The first table option buttons work, due to code running on unique option button names. eg
optIndividual
optCorporation
I create a building block based on Mortgagee table, that includes several option button groups.
When the building blocks inserted into the document, the result is default names are given to the new option button eg
optIndividual2
optCorporation2
optIndividual21
optCorporation21
I wont know the option button names, or how manys option buttons are inserted.
Is there a standard click event for option buttons, that I can capture to run on any option button selected.
Is it possible to do something similar with the checkbox macrofield, and run on option buttons
TIA dd
You do not have the required permissions to view the files attached to this post.
-
- Microsoft MVP
- Posts: 1318
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: Word 2007 - dynamic word forms checkbox or command butt
As I mentioned in passing before, ActiveX controls (which those option buttons are) require a unique name and a unique code procedure for each one. That makes them unsuitable for use in building blocks. One alternative is to use a dropdown (either a content control or a form field, though the latter then requires forms protection which could make the rest of the form a nightmare). For the content controls, you can write code in the Document_ContentControlOnExit event handler in the ThisDocument module, which fires whenever the focus leaves any content control. An argument to the event handler will tell you which control was just exited, so you can find out its value.
Another possibility, a bit more complex to program but appearing like real option buttons, is shown on a page at Greg Maxey's site.
Another possibility, a bit more complex to program but appearing like real option buttons, is shown on a page at Greg Maxey's site.
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: Word 2007 - dynamic word forms checkbox or command butt
Thanks Jay
Yes Im familiar with and have used Document_ContentControlOnExit event handler in the ThisDocument
Yes Ive come across Greg Maxeys site before – its informative. He’s using Word 2010, I’m using Word 2007 which means checkbox content controls aren’t available in 2007.
I think I need to go back to the drawing board…
Many thanks again Jay, dd
Yes Im familiar with and have used Document_ContentControlOnExit event handler in the ThisDocument
Yes Ive come across Greg Maxeys site before – its informative. He’s using Word 2010, I’m using Word 2007 which means checkbox content controls aren’t available in 2007.
I think I need to go back to the drawing board…
Many thanks again Jay, dd