Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2005

Tip: Looking for answers? Try searching our database.

do variables preserve their value after documents are saved?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ALBAN - 03 Sep 2005 14:45 GMT
I'm trying to set up a counter that tracks the number of times a certain
button has been clicked. The intention is to preserve the value (after
document is saved and closed) so the counter countinues where it stopped the
last time. Is this possible?

The way I'm doing it at the moment is:

I have created a special template for these documents that need this sort of
counting. In VBA, within the template project I have used the New event to
initialize the counter, hoping that everytime a new document from this
templated is created, it will initialize the counter to 1.
I can use counter correctly for the first time the document is used (the
time it's created by the template).
However, the next time I open the document, the counter is set to a fixed
value!

Any idea why?

thanks in advance,
ALBAN
Jonathan West - 03 Sep 2005 15:12 GMT
Show us the relevant bit of code. Variables do different things depending on
how they are declared.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> I'm trying to set up a counter that tracks the number of times a certain
> button has been clicked. The intention is to preserve the value (after
[quoted text clipped - 18 lines]
> thanks in advance,
> ALBAN
ALBAN - 03 Sep 2005 17:24 GMT
> Document New event, stored in the template:

Private Sub Document_New()
 ThisDocument.Variables("latinChar").Value = 1
End Sub

> This is the event that is supposed to do the counting:

Private Sub CommandButton1_Click()
   ThisDocument.Variables("latinChar").Value =
ThisDocument.Variables("latinChar").Value + 1
End Sub

> The button is in a form that is enabled with a macro that does the following:

Sub InsertCustomFootnotes()
 UserForm1.Show
End Sub

According to another posting, variables don't preserve their values between
sessions.
If this is correct, is there another way to achieve what I want to do?

thanks,
ALBAN

> Show us the relevant bit of code. Variables do different things depending on
> how they are declared.
[quoted text clipped - 21 lines]
> > thanks in advance,
> > ALBAN
Jonathan West - 03 Sep 2005 17:31 GMT
Ah! You're taking of Document Variables, not code variables.

Document Variables are rather like Custom Document Properties. They are
saved as part of the document and therefore remain between Word sessions
when you re-open the document.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

>> Document New event, stored in the template:
>
[quoted text clipped - 56 lines]
>> > thanks in advance,
>> > ALBAN
Jay Freedman - 03 Sep 2005 23:09 GMT
Yes, document variables are saved in the document.... but use
"ActiveDocument" instead of "ThisDocument".

--
Regards,
Jay Freedman
Microsoft Word MVP     FAQ: http://word.mvps.org

> Ah! You're taking of Document Variables, not code variables.
>
[quoted text clipped - 62 lines]
>>> > thanks in advance,
>>> > ALBAN
Jasonm - 24 Sep 2005 17:27 GMT
ALBAN, sorry to jump in on your thread, but I have a somewhat related
question:

Jonathan, if I were to try this in a document template would it also work?
Right now I am using an external txt file to store my numbers (I have 6
variables that I am incrementing). It could potentially be cleaner to store
them IN the document template if that would work.

I am using my variables to set the filename of the document to increment
document 001, document 002, etc...

any ideas?
Jason Canady

> Ah! You're taking of Document Variables, not code variables.
>
[quoted text clipped - 62 lines]
>>> > thanks in advance,
>>> > ALBAN
Doug Robbins - 26 Sep 2005 08:40 GMT
See the article "Creating sequentially numbered documents (such as
invoices)" at:

http://www.word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm

Maybe it does what you want.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> ALBAN, sorry to jump in on your thread, but I have a somewhat related
> question:
[quoted text clipped - 78 lines]
>>>> > thanks in advance,
>>>> > ALBAN
Jezebel - 03 Sep 2005 15:51 GMT
Variables don't preserve their values between sessions.

> I'm trying to set up a counter that tracks the number of times a certain
> button has been clicked. The intention is to preserve the value (after
[quoted text clipped - 18 lines]
> thanks in advance,
> ALBAN
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.