protected fields

F

Fuzzhead

I have a protected template that has a lot of fields in it the various groups
need to get into just their section of it. I have the following macro that
runs when the user enters bookmark “Text14â€. The macro opens and I can enter
info and hit OK but it does not update the fields in the template. What am I
doing wrong?


Dim frm As frmCorc
Dim oRg As Range

Set frm = New frmCorc

On Error Resume Next

With ActiveDocument
frm.tbxName.Value = .Bookmarks("Text14").Range.Text
frm.tbxDate.Value = .Bookmarks("Text13").Range.Text
frm.JHABox = .Bookmarks("Dropdown9").Range.Text
frm.tbxWhy.Value = .Bookmarks("Text41").Range.Text
End With

frm.Show

If frm.bIsOK Then
With ActiveDocument
Set oRg = .Bookmarks("Text14").Range
oRg.Text = frm.tbxName.Text
.Bookmarks.Add Name:="Text14", Range:=oRg

Set oRg = .Bookmarks("Text13").Range
oRg.Text = frm.tbxDate.Text
.Bookmarks.Add Name:="Text13", Range:=oRg

Set oRg = .Bookmarks("Dropdown9").Range
oRg.Text = frm.JHABox.Text
.Bookmarks.Add Name:="Dropdown9", Range:=oRg

Set oRg = .Bookmarks("Text41").Range
oRg.Text = frm.tbxWhy.Text
.Bookmarks.Add Name:="Text41", Range:=oRg

.Fields.Update
End With
Else
ActiveDocument.Saved = True
End If

Set frm = Nothing
End Sub
 
F

Fuzzhead

Thank you, that worked.

Now I am having a problem with a combobox. When I call up the form, the
combobox is a 'Yes No' pick but what is in the form field is 'FORMTEXT NO'.
What is going on? My code is as follows:

Private Sub UserForm_Initialize()

With JHABox
.AddItem "No"
.AddItem "Yes"

.ListIndex = 0

.MatchRequired = True
End With

End Sub

Also when I tab through my form it jumps all around instead of going in
order. Can that be fixed?
 
D

Doug Robbins - Word MVP

Once again, where is the code that is transferring the selection from the
combobox on the userform into the .Result of the FormField

It seems like you have missed that step (which would not be in the
UserForm_Initialize event, but needs to be in a CommandButton_Click event

ActiveDocument.FormFields("formfieldname").Result = JHABox

You can set the tab order on the UserForm via the Tab order item on the View
menu in the VBE

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

I suspect that the problem might be because of your using the .Text of the
bookmark range in one instance and then the .Result of the formfield in
another.

Try using the .Result of the formfields in both cases.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

frm.tbxName.Value = .FormFields("Text14").Result

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
F

Fuzzhead

That worked. Thanks....

Would I use the same format for check boxes? I have alot of checkboxes in my
template. So can I use a checkbox in my form and use the following to say if
its checked in the template, check it in the form or the othere way around?

frm.cb1.Value = .FormFields("Check86").Result
and
ActiveDocument.FormFields("Check86").Result = frm.cb1.Value
 
D

Doug Robbins - Word MVP

You should use

frm.tbxName.Value = .FormFields("Text14").CheckBox.Value.

as that returns .CheckBox.Value returns the "True" or "False", which are the
same as the settings for a Checkbox control on a UserForm.

The .Result of a checkbox formfield returns 1 or 0 and you would have to
convert that.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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