PDA

View Full Version : User Form customisation



Pogla
02-10-2010, 08:18 PM
Hey guys,

I have searched through these forums, but I cannot find exactly what I need (or I'm just being thick).

I am setting up a standard document in Word 2003 (for release management), and have put in a user form for the variables.

What I want to be able to do is show or hide some sections of text based on a checkbox value in the User Form.

The text to be shown/hidded has some formatting (one part has a header then normal text, another part has numbering).

I'm wondering weather I should put the text I want to add in a variable (in which case I need help with formatting), or put it into a field and have it hidden by default, and only unhidden when the checkbox is selected (in which case I need help with the code).

Also, I have coded the button to update the document from the form field, but I want to have another button to update just the DocVariable fields.

Code for updating all fields:

Private Sub UpdateButt_Click()
'Keep the cursor at the top of the page
Application.ScreenUpdating = False
'input variables
With ActiveDocument
.Variables("ContactNo").Value = ConNumTxt.Value
.Variables("Requestor").Value = RequestorTxt.Value
.Variables("DBname").Value = DBnameTxt.Value
.Variables("LinkedSrv").Value = LinkSrvTxt.Value
.Variables("ODBCsource").Value = ODBCsourceTxt.Value
.Variables("ODBCtarget").Value = ODBCtargetTxt.Value
.Variables("VerNum").Value = VerTxt.Value
.Variables("LinkVar").Value = "Not Applicable"
End With

ActiveDocument.Fields.Update

Application.ScreenUpdating = True

Unload Me

End Sub

lucas
02-11-2010, 08:58 AM
There are a couple of ways to do this. One is to put all the text in question in bookmarks and delete all except the one you want.

Another is to set styles and show or hide by changing the style.

Is the following a formfield, bookmark?

.Variables("ContactNo").Value

fumei
02-11-2010, 09:38 AM
"Is the following a formfield, bookmark?"

Huh? It seems to be what it says it is, a Variable.

I am confused though. What have the Variables have to do with hiding text?

Further: "Also, I have coded the button to update the document from the form field, but I want to have another button to update just the DocVariable fields."

What is the problem? Have a button to update the DocVariable fields, which you seem to have already. But I do not know what you mean by "update the document from the form field. WHAT formfield? Update the document from the formfield? What does that mean?

lucas
02-11-2010, 09:54 AM
so if I delcare it as string and use it like this:
contactno = ConNumTxt.Value
MsgBox contactno

it works. But not the way the poster is using it.....

I'm probably missing something but it just didn't seem right to me?

fumei
02-11-2010, 10:08 AM
With ActiveDocument
.Variables("ContactNo").Value = ConNumTxt.Value
simply makes the variable that value.

Word VBA is rather polite in this case. You do NOT need to use an .Add instruction first:
ActiveDocument.Variables.Add "Whatever", "Yipppeee"
If "Whatever" does not exist, and you code:

ActiveDocument.Variables("Whatever").Value = "Yipppeee"
Word will create the DocVariable and give it that value.

My question, though, is what does this have to do with hiding/showing chunks of text?

lucas
02-11-2010, 10:22 AM
but this doesn't work Gerry:

Private Sub CommandButton1_Click()
Dim contactno As String
With ActiveDocument
.Variables("ContactNo").Value = ConNumTxt.Value
' contactno = ConNumTxt.Value

MsgBox contactno
End With

End Sub


It returns an empty msgbox. I'm still missing something.

lucas
02-11-2010, 10:25 AM
here's my example Gerry.

fumei
02-11-2010, 11:03 AM
"I'm still missing something."

Indeed.

1. you declare contactno as a string
2. you never give that string a value....because you are giving a Variable - ActiveDocument.Variables("ContactNo") - the value!

ergo: the string contactno is empty, so:
MsgBox contactno
will return...an empty string.

Try:
Private Sub CommandButton1_Click()
Dim contactno As String
With ActiveDocument
.Variables("contactno").Value = ConNumTxt.Value
MsgBox ActiveDocument.Variables("contactno").Value
End With

End Sub
It displays the .Value of the Variable "contactno" i.e. the .Value of ConNumTxt (assuming the textbox HAS a value.

BTW: again, I would encourage the use of .Text, rather than .Value to get the text value from a textbox control.

File back atcha.

lucas
02-11-2010, 11:10 AM
ah, I follow now Gerry. Thanks. That makes sense.

I'm just used to the shorthand.

Pogla
02-11-2010, 04:34 PM
Hey guys.

Thanks HEAPS for your quick responses.

Lucas, using custom styles works a treat.

Fumei, thanks for your suggestions

I owe you both a beer.

The code I submitted was in an effort to get my second problem solved - updating JUST the DocVariable fields. The DocVariables are parsed from the text boxes in the Userform (suffix Txt) and then updated in the document.

I have a couple of Fill-In fields in the document that I don't neccissarily want to update. If this is more trouble then it is worth, I will just push out the document as is.

YOU GUYS ROCK!!

Pogla
02-18-2010, 06:30 PM
deleted, I fixed my own stupid mistakes