Checkbox advice needed

F

fedude

I'm trying to create a word document that will contain meeting minutes. At
the bottom of the document, I want to have a series of checkboxes for the
attendees to electronically approve the minutes. If they check it it means
they approve the minutes.

Once the person checks the box, the control needs to become disabled so they
cannot reverse their decision and the "approved" record is retained in the
document

I don't know if I should start by just putting some forms controls directly
in a table in the document. This looks the best, but I can't quite figure
out how to disable each control after it is checked. Or would it be better
to create a form and then somehow embed the form in the document (not sure if
this is even possible).

Bonus points if there is a way to password protect each checkbox.

I'm rooking for some direction from people knowledgable in word programming.
 
J

Jay Freedman

The following macro, if assigned as the Exit macro for each of the check
boxes, will disable the current box if the box is checked when you tab or
click out of the box.

Sub ExitCheckBox()
Dim oFF As FormField
Dim oCB As CheckBox

If Selection.FormFields.Count = 0 Then Exit Sub

Set oFF = Selection.FormFields(1)
If oFF.Type <> wdFieldFormCheckBox Then Exit Sub

Set oCB = oFF.CheckBox
If oCB.Value = True Then
oFF.Enabled = False
End If
End Sub

The sticky part is where to store the macro. If you store it in the template
on which the minutes document is based, then everyone who approves a
document also needs to have a copy of the template on their computer. If you
store the macro in the document itself, then Word will pester each user
about how macros in documents might be viruses, and will want to disable the
macro by default. It isn't pretty.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
F

Fumei2 via OfficeKB.com

"I don't know if I should start by just putting some forms controls directly
in a table in the document."

Why a table?

If you use ActiveX controls (from the Controls toolbar), a checkbox named
chkApproved can be made to function as you want. In the ThisDocument code
module have:

Private Sub chkApproved_Change()
If chkApproved.Value = True Then
chkApproved.Enabled = False
End If
End Sub


Private Sub chkApproved_Click()
MsgBox "Now checked as Approved." & _
vbCrLf & _
"Once approved, changes are not permitted."
End Sub

The checkbox is checked, and they get the message (from the _Click event)
"Now checked as Approved. Once approved, changes are not permitted." The
_Change event now fires and the control is disabled.

It is now checked, but it can not be changed by the user.

But.....

If the user knows VBA this can easily be altered by writing a simple
procedure that enables the control.

Sorry, but there is no way around this. Oh you can try, but again, if the
person knows what they are doing, you could not really stop them.

Password protect the chekcboxes? Nope. Why would you? To stop therm
checking it in the first place.

Although, it depends on what you are actually asking for.

Say you have individual checkboxes like:

Thomas Edison [checkbox] APPROVED
Golda Meir [checkbox] APPROVED
Frank Zappa [checkbox] APPROVED
Harley Davidson [checkbox] APPROVED

With each checkbox named appropriately, then......depending on the username
logged it is possible (but in no way fully secure) to do some sort of testing.


Private Sub chkApproved_Change()
If Environ("username") <> "thomas.edison" Then
MsgBox "This checkbox is not assigned to your system " & _
"logon name."
chkApproved.Value = False
Exit Sub
End If
If chkApproved.Value = True Then
chkApproved.Enabled = False
End If
End Sub


Private Sub chkApproved_Click()
If Environ("username") = "thomas.edison" Then
MsgBox "Now checked as Approved." & _
vbCrLf & _
"Once approved, changes are not permitted."
Else ' NOT Thomas Edison
chkApproved.Value = False
End If
End Sub

Note that the above returns messages twice, which would be annoying. This
could be fixed by using a separate Boolean Public variable. I am just point
the above out as an example of a possible route to linking specific
checkboxes to an individual - if that is what you are wanting to do.
 
C

Clinton Trocchio

Mr. Freedman,

Regarding your macro listed (Checkbox Disabling)..How would a developer
draft code that filled-in the curent user's 'username' into an adjacent cell
after that user checks a box?

For example:
User completes task 'A'. User checks it off (by clicking checkbox), and the
adjacent cell to that checkbox auto-fills their username?

In this instance, I'd be looking for the individual's username as logged
onto the INTRANET, not the username attached to the software license.

Thanks,
C-TRO

url:http://www.ureader.com/msg/102212779.aspx
 
J

Jay Freedman

Code for getting the user's network login name is at
http://www.word.mvps.org/FAQs/MacrosVBA/GetCurUserName.htm.

That may or may not be the same as the name used to log into the
current profile, which can be retrieved with the statement

MsgBox Environ$("username")

If the adjacent cell contains a text form field, you can simply assign
the username to that field's .Result using one of these statements,
depending on which way you get the username:

ActiveDocument.FormFields("Text1").Result = GetUserName
or
ActiveDocument.FormFields("Text1").Result = Environ$("username")

(Of course, replace "Text1" with the name of the form field.)

Instead of a form field, you could insert the name at a preexisting
bookmark, or just use the .Range of the adjacent cell (but you'd need
to know the coordinates of that cell); in either of these cases, the
code would have to unprotect the document, insert the text, and
reprotect the document.

By the way, it's fairly difficult to get the name attached to the
software license by using VBA. You'd have to use the
GetPrivateProfileString function to retrieve the RegOwner value from a
registry key under
HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\UserData, and
that key's name depends on the version of Office, who installed it,
and whether it was installed for the whole machine or for a specific
user profile.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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