PDA

View Full Version : Solved: Conditional Checkboxes and Hidden Bookmark Fields



Dr@g0nfly
02-21-2007, 12:51 PM
HI there, my very first post. I was modifying one of the code samples I found here uploaded by fumei (article 754). The only change I needed was to make the text APPEAR when the checkmark is chosen and HIDE when it is not. I changed the bookmark text to hidden and switched around the arguments to look like this:

Option Explicit
Private Sub ExCstID_Change()
Call ExistingCustomer
End Sub

Private Sub NExCstID_Change()
Call NoExistingCustomer
End Sub

Sub ExistingCustomer()
Dim orange As Range
Set orange = ActiveDocument.Bookmarks("ExstCustID").Range
If ExCstID.Value = True Then
With orange.Font
.Hidden = False
End With
With ActiveWindow.View
.ShowHiddenText = True
.ShowAll = False
End With
Else
With orange.Font
.Hidden = True
End With
With ActiveWindow.View
.ShowHiddenText = False
.ShowAll = False
End With
End If
End Sub

Sub NoExistingCustomer()
Dim orange As Range
Set orange = ActiveDocument.Bookmarks("NExstCustID").Range
If NExCstID.Value = True Then
With orange.Font
.Hidden = False
End With
With ActiveWindow.View
.ShowHiddenText = True
.ShowAll = False
End With
Else
With orange.Font
.Hidden = True
End With
With ActiveWindow.View
.ShowHiddenText = False
.ShowAll = False
End With
End If
End Sub
The first checkbox is a Yes checkbox to the question "Is there an existing Customer ID you would like to attach this account to?" [or some variation of that sort] and the next checkmark is NO. I need text to appear in both cases, whether they select yes or no but it seems like this code uncovers every bookmark in the document when I click every option (yes & no). I need the show property to be more discriminating. I know this must be simple to experienced programmers but I'm lost! I've only really programmed VBA in Access... Word is a little out of my field.:think:

Thanks for the help!: pray2:
~C

added code tags ~Tommy

fumei
02-21-2007, 02:40 PM
I am having a little difficulty following your post, but I think you are saying you want to selectively have hidden text.

1. Please use the VBA code tags for posting code. It makes it a lot easier for us to read.

2. ShowAll can apply to EITHER a Range, or a View. If you use it for View, then it applies to everything in that View. If I understand correctly, you may want to explicitly make your ranges hidden, or not. And don't use View.

Hard to say. Can you post a document?

Also, is to deal with 3 bookmarks (ie. a low number), or 30 bookmarks (a higher number)? The scale of the problem can change what is the best solution.

Generally speaking, IMO, user input and logic (if user selects THIS, then do THAT) handles better on a userform. Now it looks like this may BE for a userform. If so, you need to tell us these things.

Off the top of my head, without seeing the document, I would say deal with the Range of the bookmark, and leave the View alone. Just to demonstrate why I an not sure....If NExCstID.Value = True Then
With orange.Font
.Hidden = False
End With
With ActiveWindow.View
.ShowHiddenText = True
.ShowAll = False
End With
If NExCstID.Value = True Then
make the range text NOT hidden, and show hidden text.

Ummmm, if the text is not hidden...why are you showing hidden text? Who cares? The text is not hidden. I must be missing something.

Dr@g0nfly
02-21-2007, 03:02 PM
HI sorry about the tags (??) I'll look into how to use them! Yes I can see what you mean about the .hidden and not having to see everything. For about 7 yes/no questions I have to set up text to appear in response. In the case of a "yes" to the "IS there an existing customer ID" I am providing a text field so they can enter that value. [VBA]


Userform? I always get turned around with the different names. I know I don't want dialog boxes, I want fill in the blank. I believe that this is called a userform.

You are correct, if I can make each bookmark a range, then I would want to determine when each range is shown or hidden.

I wouldn't mind putting If/Then constructs, I just don't know how to enter anything other than If field1 = something Then field2 = "something". If that would be better, I would appreciate the help!

fumei
02-22-2007, 12:38 PM
You are using a _Change event. that means to me you are using a userform.

A userform IS a dialogbox of sorts. You create one in the VBE (Visual Basic Editor). You display it with a .Show instruction.

Please describe what you are doing.

Dr@g0nfly
02-22-2007, 01:04 PM
I think I might have got it with this go around:

Sub ExstCust_Change()
Call ShowHideCustID
End Sub

Private Sub NExstCust_Click()
Call Form_Load
End Sub

Private Sub ShowHideCustID()
Dim orange As Range
Set orange = ActiveDocument.Bookmarks("ExstCustID").Range
If ExstCust.Value = True Then
With orange.Font
.Hidden = False
End With
Else
With orange.Font
.Hidden = True
End With
End If
End Sub

Private Sub Form_Load()
If NExstCust.Value = True Then
MsgBox "GBPS will generate a Customer ID.", vbExclamation, "Header"
End If
End Sub

The only problem is that I can't seem to make the two checkbox controls exclusive....
Thank you for all of your help!

Dr@g0nfly
02-22-2007, 01:09 PM
PS! I am not using a userform but attempting to produce a document with fill in fields. Perhaps I am using the wrong elements in the Word doc but it needs to remain a word doc or at most be transferred to a web form (by the company's TECH team). I have no .showinstruction commands in VBE.

fumei
02-23-2007, 11:11 AM
Please explain...Sub ExstCust_Change()
Call ShowHideCustID
End Sub WHAT is ExstCust?

If it is not a control on a userform, I guess it can only be an ActiveX control. Did you use the Controls toolbar to put in...whatever is ExstCust?

If so, please please, in your posts tell us the actual situation. We can not see your computer, and we can not read minds, and "ExstCust" is a poorly named something. It tells me nothing.

BTW: using a userform does not do anything to a document. A document is a document is a document.

If they ARE ActiveX controls, and they are checkboxes - is ExstCust a checkbox?...who knows? - then perhaps you would be better off using OptionButtons. You can group them. The user can pick one OR the other.

Dr@g0nfly
03-02-2007, 03:24 PM
Yes this is an activeX control. As I have had to work these items I have become more familiar with their names. I inserted ActiveX controls to allow the user to narrow the questions that they need to answer based on their answers to key questions. Thanks for the help!