
Storing Variables 2 Display in UserForm
Hi there,
The code below is exactly except I haven't put up to 10
witnesses. I hope it makes sense...
'this bit below puts the user's input into the variable
Private Sub CmdOK_Click()
Me.Hide
ActiveDocument.Variables("witness1").Value = Me.tbox1.Text
ActiveDocument.Variables("witness2").Value = Me.tbox2.Text
(up to witness10)
'then this bit is if they enter a blank don't get an
error box saying object deleted
If Me.tbox1.Text = "" Then
ActiveDocument.Variables("witness1").Value = " "
End If
If Me.tbox2.Text = "" Then
ActiveDocument.Variables("witness2").Value = " "
(up to witness10)
End Sub
'This bit below should put the names back into the
textbox when the form is re-opened.
Private Sub FormNames_Initialize()
Me.tbox1.Text = ActiveDocument.Variables("witness1").Value
Me.tbox2.Text = ActiveDocument.Variables("witness2").Value
(up to witness10)
End Sub
'press this to print out the name
Sub WitnessN1() ' 1 on toolbar
Dim ad As Document
Set ad = ActiveDocument
Selection.Text = ad.Variables("witness1").Value
Selection.MoveRight Unit:=wdCharacter, Count:=4
End Sub
'the variables are created
Sub VariablesSetup()
Dim ad As Document
Set ad = ActiveDocument
ad.Variables.Add Name:="witness1", Value:="witness 1"
(up to witness 10)
End Sub
Thanks,
Siobhan
Quote:
>-----Original Message-----
>It would help if you showed us the code you use to create
the docment
>variables.
>Maybe they are not where you think they are or maybe they
are not being
>created / saved properly?
>Cheers!
>--
>_________________________________________
>Jean-Guy Marcil
message de
>> Hello,
>> I've created a userform where the user can input 10
names
>> into 10 textboxes. Then, the names are saved in numbered
>> variables which are then attached with
selection.typetext
>> to the menu bar so the user can just press ALT 1 to ALT
10
>> instead of retyping the whole name again. The problem is
>> when the user saves and closes the document, and reopens
>> it attached to the same template, when the userform is
>> initialised the names they had typed in the textboxes
>> aren't in there although I've done:
>> Private Sub FormNames_Initialize()
>> Me.tbox1.Text = ActiveDocument.Variables
("witness1").Value
>> etc.
>> so that the contents in the variable are reloaded back
>> into the form textboxes.
>> Could anyone help?
>> Thanks,
>> Siobhan
>.