Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2016, 05:53 AM
AttiCuS AttiCuS is offline Form fields and bookmarks restrictions Windows 7 32bit Form fields and bookmarks restrictions Office 2010 32bit
Novice
Form fields and bookmarks restrictions
 
Join Date: Mar 2016
Posts: 6
AttiCuS is on a distinguished road
Question Form fields and bookmarks restrictions

Hi,

I'm new here and also I'm new in working with Word forms. I have intermediate experience with Excel VBA.

I attached Word file on which I'm working, but without success.

What I want to do is set a restriction for drop-down form field. Is it possible at all to restrict each form field to be visible or not? If not, maybe it is possible to set each form field as inactive.

E.x.:
1. If we choose A from drop down field then some form fields (bookmarks) are not visible.
2. If we choose B from drop down field then bookmark "bye" and "restriction" are not visible with formatting (line below "Bye")
3. If checked "yes" then all formfields (bookmarks) are not visible.

As said I'm new and not sure what is difference between form field and bookmark. To do mentioned points should I use VBA code or can I just work on Cross-reference?

Please advise me, I attached example file.



Regards,
AttiCuS
Attached Files
File Type: docx Form fields.docx (17.3 KB, 13 views)
Reply With Quote
  #2  
Old 04-06-2016, 06:22 AM
macropod's Avatar
macropod macropod is offline Form fields and bookmarks restrictions Windows 7 64bit Form fields and bookmarks restrictions Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,365
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It is not possible to conditionally show/hide formfields. Doing that or conditionally enabling/disabling them would require a macro. Also, instead of Yes and No checkboxes, you should consider having a single dropdown with Yes/No choices. That way, there's no risk of both being checked. Field coding can be used to conditional show/hide your 'Bye' & 'Restriction' text.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-07-2016, 01:44 AM
AttiCuS AttiCuS is offline Form fields and bookmarks restrictions Windows 7 32bit Form fields and bookmarks restrictions Office 2010 32bit
Novice
Form fields and bookmarks restrictions
 
Join Date: Mar 2016
Posts: 6
AttiCuS is on a distinguished road
Default

Hi macropod,

Thank you for your replay. I tried to add simple VBA code, however without any success.

What I want to do is: when I choose 'A' from 'drop_list' then in 'Text1" should appear text: 'xxx'. I used this code:

Sub OnExitCB1B()
If ActiveDocument.drop_list = "A" Then
ActiveDocument.FormFields("Text1").Result = "xxx"
End If
End Sub

But it doesn't work :-(

Could you give an example how could look macro for enabling/disabling formfields?

The case is that I have protected form to be filled. To start filling the template/form we have to choose one option from dropdown list. Then we get an info/text in the formfield below. And what is the most important depend by what we choose from dropdown some section in the document should be enabled/disabled to edit. What you can see each text, like 'Hello' or 'Bye' is added as formfield with disabled fill-in option.

I was thinking also about adding text next to different heading. E.x.: when you choose 'A' from dropdown next to 'Bye" should appear text -'do not fill this section'.

I'm just learning it and for now it is black magic for me ;-) I see that you have large experience in work with MS Word. I would really appreciate if you could show me the road how to solve it.

Regards,
AttiCuS
Attached Files
File Type: docm Form fields.docm (25.3 KB, 15 views)
Reply With Quote
  #4  
Old 04-07-2016, 02:06 AM
macropod's Avatar
macropod macropod is offline Form fields and bookmarks restrictions Windows 7 64bit Form fields and bookmarks restrictions Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,365
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Here's some code to get you started. Note that I've included a reference to 'chbx_yes2', but the corresponding checkbox lacks the bookmark name.
Code:
Sub OnExitCB1B()
With ActiveDocument
  Select Case .FormFields("drop_list").Result
    Case "A"
      .FormFields("Text1").Result = "xxx"
      With .FormFields("Dropdown_yes_no")
        .DropDown.Value = .DropDown.Default
        .Enabled = False
      End With
      With .FormFields("chbx_yes2")
        .CheckBox.Value = False
        .Enabled = False
      End With
      With .FormFields("chbx_no2")
        .CheckBox.Value = False
        .Enabled = False
      End With
    Case "B"
      .FormFields("Dropdown_yes_no").Enabled = True
      .FormFields("chbx_yes2").Enabled = True
      .FormFields("chbx_no2").Enabled = True
    Case "C"
      .FormFields("Dropdown_yes_no").Enabled = True
      .FormFields("chbx_yes2").Enabled = True
      .FormFields("chbx_no2").Enabled = True
  End Select
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-13-2016, 04:43 AM
AttiCuS AttiCuS is offline Form fields and bookmarks restrictions Windows 7 32bit Form fields and bookmarks restrictions Office 2010 32bit
Novice
Form fields and bookmarks restrictions
 
Join Date: Mar 2016
Posts: 6
AttiCuS is on a distinguished road
Default

Hi macropod,

Thanks, it works perfect!

However, I have one more issue, which can't solve.

Code:
Private Sub Document_Close()
  Select Case ActiveDocument.FormFields("drop").Result
    Case "Internal"
    If ActiveDocument.FormFields("mob_ph_check").CheckBox.Value = False And ActiveDocument.FormFields("broad_check").CheckBox.Value = False And ActiveDocument.FormFields("car_check").CheckBox.Value = False And ActiveDocument.FormFields("vsp_check").CheckBox.Value = False Then
        MsgBox "Are you sure that contract should be without benefits?", vbOKOnly
        Cancel = True
    End If
    Case "Permanent"
    If ActiveDocument.FormFields("mob_ph_check").CheckBox.Value = False And ActiveDocument.FormFields("broad_check").CheckBox.Value = False And ActiveDocument.FormFields("car_check").CheckBox.Value = False And ActiveDocument.FormFields("vsp_check").CheckBox.Value = False Then
        MsgBox "Are you sure?", vbOKOnly
        Cancel = True
    End If
  End Select
End Sub
I used this code to run action. When I choose 'Internal' or 'Permanent' from formfield 'drop' and couple of checkboxes are not checked then want to close the file I get a message. And then I have a possibility to save file, don't save or cancel and back to file and continue filling form.

Is it possible to run the same action if I click 'Save' - little disk in the left upper corner?

Best regards,
AttiCuS
Reply With Quote
  #6  
Old 04-13-2016, 05:01 AM
macropod's Avatar
macropod macropod is offline Form fields and bookmarks restrictions Windows 7 64bit Form fields and bookmarks restrictions Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,365
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You might try using a macro like:
Code:
Sub FileSave()
Call Document_Close
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 04-13-2016, 11:01 PM
AttiCuS AttiCuS is offline Form fields and bookmarks restrictions Windows 7 32bit Form fields and bookmarks restrictions Office 2010 32bit
Novice
Form fields and bookmarks restrictions
 
Join Date: Mar 2016
Posts: 6
AttiCuS is on a distinguished road
Default

Such a shame that was so easy

However, have one more question. I little modified my code insteady of vbOKOnly I used vbYesNoCancel. And now I don't know how to assign 'No' and 'Cancel'. If someone choose No or Cancel should go back to file with possible to continue filling the form. So, won't get question 'Do you want to save changes you made to...'

Could you help me with that, as well?

Anyway, I'm really grateful for your help so far

Regards,
AttiCuS
Reply With Quote
  #8  
Old 04-16-2016, 11:12 PM
macropod's Avatar
macropod macropod is offline Form fields and bookmarks restrictions Windows 7 64bit Form fields and bookmarks restrictions Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,365
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In that case, you might use something like:
Code:
Private Sub FileSave()
Call FieldCheck
End Sub
 
Private Sub Document_Close()
Call FieldCheck
End Sub
 
Private FieldCheck()
  Select Case ActiveDocument.FormFields("drop").Result
    Case "Internal"
    If ActiveDocument.FormFields("mob_ph_check").CheckBox.Value = False And ActiveDocument.FormFields("broad_check").CheckBox.Value = False And ActiveDocument.FormFields("car_check").CheckBox.Value = False And ActiveDocument.FormFields("vsp_check").CheckBox.Value = False Then
        MsgBox "Are you sure that contract should be without benefits?", vbOKOnly
    End If
    Case "Permanent"
    If ActiveDocument.FormFields("mob_ph_check").CheckBox.Value = False And ActiveDocument.FormFields("broad_check").CheckBox.Value = False And ActiveDocument.FormFields("car_check").CheckBox.Value = False And ActiveDocument.FormFields("vsp_check").CheckBox.Value = False Then
        MsgBox "Are you sure?", vbOKOnly
    End If
  End Select
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 04-18-2016, 06:41 AM
AttiCuS AttiCuS is offline Form fields and bookmarks restrictions Windows 7 32bit Form fields and bookmarks restrictions Office 2010 32bit
Novice
Form fields and bookmarks restrictions
 
Join Date: Mar 2016
Posts: 6
AttiCuS is on a distinguished road
Default

Hi macropod,

Thank you for an example.

However, it was not my intend.

Now I saved my file as Microsoft Word Macro-Enabled Template.

I want to use vbYesNoCancel buttons.

But, I don't know how to assign each button. When someone choose 'Yes' the macro should let save the file, even if clicked 'Save' - little disk in left upper corner or want to close the file by pressing 'X'. But, if someone choose 'No' or 'Cancel' should go back to file with possible to continue filling the form. So won't get system question 'Do you want to save changes you made to...'.

Code:
Private Sub Document_Close()
  Select Case ActiveDocument.FormFields("drop").Result
    Case "Internal"
    If ActiveDocument.FormFields("mob_ph_check").CheckBox.Value = False And ActiveDocument.FormFields("broad_check").CheckBox.Value = False And ActiveDocument.FormFields("car_check").CheckBox.Value = False And ActiveDocument.FormFields("vsp_check").CheckBox.Value = False Then
        MsgBox "Are you sure that contract should be without benefits?", vbYesNoCancel
        Cancel = True
    End If
    Case "Permanent"
    If ActiveDocument.FormFields("mob_ph_check").CheckBox.Value = False And ActiveDocument.FormFields("broad_check").CheckBox.Value = False And ActiveDocument.FormFields("car_check").CheckBox.Value = False And ActiveDocument.FormFields("vsp_check").CheckBox.Value = False Then
        MsgBox "Are you sure?", vbYesNoCancel
        Cancel = True
    End If
  End Select
End Sub
 
Sub FileSave()
Call Document_Close
End Sub
Reply With Quote
  #10  
Old 04-18-2016, 02:16 PM
macropod's Avatar
macropod macropod is offline Form fields and bookmarks restrictions Windows 7 64bit Form fields and bookmarks restrictions Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,365
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In that case you could use code like:
Code:
Private Sub Document_Close()
Dim Rslt As Long
    Select Case ActiveDocument.FormFields("drop").Result
    Case "Internal"
    If ActiveDocument.FormFields("mob_ph_check").CheckBox.Value = False And ActiveDocument.FormFields("broad_check").CheckBox.Value = False And ActiveDocument.FormFields("car_check").CheckBox.Value = False And ActiveDocument.FormFields("vsp_check").CheckBox.Value = False Then
        Rslt = MsgBox("Are you sure that contract should be without benefits?", vbYesNoCancel)
        Select Case Rslt
            Case vbYes
            Case vbNo
            Case vbCancel
       End Select
    End If
    Case "Permanent"
    If ActiveDocument.FormFields("mob_ph_check").CheckBox.Value = False And ActiveDocument.FormFields("broad_check").CheckBox.Value = False And ActiveDocument.FormFields("car_check").CheckBox.Value = False And ActiveDocument.FormFields("vsp_check").CheckBox.Value = False Then
        Rslt = MsgBox("Are you sure?", vbYesNoCancel)
        Select Case Rslt
            Case vbYes
            Case vbNo
            Case vbCancel
       End Select
    End If
  End Select
End Sub
Simply flesh out the Case statements with whatever you want to have happen when the user presses Yes, No or Cancel.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 04-19-2016, 01:52 AM
AttiCuS AttiCuS is offline Form fields and bookmarks restrictions Windows 7 32bit Form fields and bookmarks restrictions Office 2010 32bit
Novice
Form fields and bookmarks restrictions
 
Join Date: Mar 2016
Posts: 6
AttiCuS is on a distinguished road
Default

Hi macropod,

You turned me to good way, as always

However, still don't have any idea how to 'bite' it ;-)

Code:
         Select Case Rslt
            Case vbYes
            Me.Saved = True
            Case vbNo
            Exit Sub
         End Select
I've changed the button option to vbYesNo. But it doesn't work;/

When clicked little disk to save the file, I got question and this is ok. However when I chose button 'Yes' or 'No' nothing has happened.

I want to make the action if I click X to close the file I got the question - and it works. Then when I choose 'Yes' the file should be saved but when choose 'No' I want to go back to file without system question if I want save the file and then continue filling template. The same action if I click little disk to save the file.

Could you help me with that also?
Reply With Quote
  #12  
Old 04-19-2016, 02:40 AM
macropod's Avatar
macropod macropod is offline Form fields and bookmarks restrictions Windows 7 64bit Form fields and bookmarks restrictions Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,365
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Perhaps:
Code:
Private Sub Document_Close()
Dim Rslt As Long, bStatus As Boolean
With ActiveDocument
    bStatus = (.FormFields("mob_ph_check").CheckBox.Value = False And _
      .FormFields("broad_check").CheckBox.Value = False And _
      .FormFields("car_check").CheckBox.Value = False And _
      .FormFields("vsp_check").CheckBox.Value = False)
    Select Case .FormFields("drop").Result
    Case "Internal"
    If bStatus = True Then
        If MsgBox("Are you sure that contract should be without benefits?", vbYesNo) = vbYes Then .Save
    Else
      .Save
    End If
    Case "Permanent"
    If bStatus = True Then
        If MsgBox("Are you sure?", vbYesNo) = vbYes Then .Save
    Else
      .Save
    End If
  End Select
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to keep formatted form fields after mail merge or replace text with formatted form fields jer85 Word VBA 2 04-05-2015 10:00 PM
Form fields and bookmarks restrictions Form updating Bookmarks - writes to the bookmarks multiple times PeterPlys Word VBA 13 01-14-2015 06:41 AM
Form fields and bookmarks restrictions How To Find Bookmarks and/or custom fields Inside Building Blocks, Office 2010 thpanos Word 3 02-17-2013 08:49 AM
Form fields and bookmarks restrictions Form Fields - Create blank form text field with if statement? LAssist2011 Word 5 12-14-2011 03:02 PM
autopopulating REF fields + bookmarks valz Word 10 09-01-2011 08:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:27 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft