Storing Variables 2 Display in UserForm 
Author Message
 Storing Variables 2 Display in UserForm

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



Sat, 05 Nov 2005 02:37:40 GMT  
 Storing Variables 2 Display in UserForm
yo shivers,

To do what you have described, you need to be able to save the data between
Word sessions. There are a number of ways to do that, depending on your
needs, abilities, and environment:

1. Document Variables - use this if the data is specific to a document.
(Check out ActiveDocument.Variables())

2. Registry Settings  - use this if the data is specific to a computer
(check out SaveSetting and GetSetting)

3. Private .ini files - Can be used on a single machine or across a network
for multiple users. check out (System.PrivateProfileString) Less common (?)
these days since registry entries became the rage, but I still use them
occasionally. Makes for transporting data between computers easier than
registry settings and easier to edit and drop new data on a user than a
registry.

4. External network text files or database - use either of these if the data
needs to be accessible to many users simultaneously. Many different access
methods including the filesystemobject or sequential text files for text
files or any number of database access methods, depending on the database.

HTH and have a great day.

Steve


Quote:
> 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



Sun, 06 Nov 2005 22:08:33 GMT  
 Storing Variables 2 Display in UserForm
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



Quote:
> 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



Sun, 06 Nov 2005 23:01:36 GMT  
 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

>.



Mon, 07 Nov 2005 01:56:50 GMT  
 Storing Variables 2 Display in UserForm
Hi Siobhan,

Next to the options provided by the other respondees,
you might consider using CustomDocumentProperties and
DocProperty fields in the document instead.

Document variables are volatile where as CustomDocumentProperties aren't.

How to work with document properties
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odeo...

How to insert DocProperty fields
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnov...
ml/wordfieldsparti.asp

If the names of your userform textboxes are synchronized to the names of yr
custom document property fields, following example transfers values
from yr userform textboxes to the document properties

Dim cdp as DocumentProperty
For each cdp in ActiveDocument.CustomDocumentProperties
    cdp = Me.Controls(cdp.Name).Value
Next

Krgrds,
Perry



Quote:
> 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



Tue, 08 Nov 2005 06:18:33 GMT  
 Storing Variables 2 Display in UserForm
Thanks v much Perry - I'll give it a go.

Siobhan

Quote:
>-----Original Message-----
>Hi Siobhan,

>Next to the options provided by the other respondees,
>you might consider using CustomDocumentProperties and
>DocProperty fields in the document instead.

>Document variables are volatile where as

CustomDocumentProperties aren't.
Quote:

>How to work with document properties
>http://msdn.microsoft.com/library/default.asp?

url=/library/en-us/odeopg/html
Quote:
>/deovrworkingwithdocumentproperties.asp

>How to insert DocProperty fields
>http://msdn.microsoft.com/library/default.asp?

url=/library/en-us/dnovba00/ht
Quote:
>ml/wordfieldsparti.asp

>If the names of your userform textboxes are synchronized
to the names of yr
>custom document property fields, following example
transfers values
>from yr userform textboxes to the document properties

>Dim cdp as DocumentProperty
>For each cdp in ActiveDocument.CustomDocumentProperties
>    cdp = Me.Controls(cdp.Name).Value
>Next

>Krgrds,
>Perry



>> 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

>.



Sat, 12 Nov 2005 20:44:52 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Where to store variables from UserForm?

2. show userform when name is stored in variable

3. Displaying results of querydef in a form or storing it as a variable for later use

4. Variable(s) Reset by Showing 2nd UserForm on top 1st UserForm

5. Passing a Variable from one Userform to another Userform

6. Two Questions - Making a userform active / Accessing a userform via a variable

7. Displaying Another UserForm when click on CheckBox in UserForm

8. Referencing a variable name stored in a variable

9. Userform to store data

10. userform to return value stored in excel book...


 
Powered by phpBB® Forum Software © phpBB Group