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 / December 2006

Tip: Looking for answers? Try searching our database.

Need to be able to "store" and "write" variables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steven G - 19 Dec 2006 05:22 GMT
I have a userform built into a document template that holds numerous
variables (Multipage) with navigation and "Save" and "Exit" coded buttons.  
When the user gets to the last page of the form and clicks the save button it
writes the variables into the document in set bookmarks.  What I would like
to be able to do is:

Take certian "information" variables and "store" them into a plain text
document for backup purposes, and during the time the userform is active,
periodically update the plain text with the most current information in the
variables.  This file would be used in case of crash to copy text from and
into a different document manually if needed.

I also am looking for a way to check for any other open word documents, and
make sure that the userform document (the one opened from the template) has
the focus before it starts excuting it's code.

I have searched hi and low for examples, samples and I believe I may asking
the wrong questions to get the correct answers for my problems.

Thanks,

Signature

Steven G
"One Day at a Time"

Doug Robbins - Word MVP - 19 Dec 2006 18:17 GMT
Check out the use of the system.privateprofilestring function.

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

>I have a userform built into a document template that holds numerous
> variables (Multipage) with navigation and "Save" and "Exit" coded buttons.
[quoted text clipped - 22 lines]
>
> Thanks,
Steven G - 28 Dec 2006 05:11 GMT
Thanks Doug for the direction.  I however am still running into the same type
of problem only with different error messages and am running myself ragged
trying to get the syntax right.  Here is what I have so far:

Sub MakeBkup()
   Dim strBodyText As String
   
   With UserForm2
       ' combine the individual text boxes into a string and write to a
backup text file
       
       strBodyText = UserForm2.AnnounceNum & UserForm2.SummaryText &
UserForm2.ProfileText & UserForm2.ResponText & UserForm2.QualifText
       System.PrivateProfileString("c:\usr\solarbackup.txt", "SOLARBackup",
"Text") = strBodyText
   End With
End Sub

I am also still fighting with trying to "grab" the current window the
template creates when it starts, so when the code is excuted it starts
running in the correct document.  This is what I have for that:

Option Explicit
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,
ByVal hWndNewParent As Long) As Long
Public WithEvents appword As Word.Application

Public Sub Document_New()
    Dim strName As String
    Dim iHandleDoc As Long
    Dim iHandleForm As Long
    Dim iNull As Long
   
    iHandleDoc = GetActiveWindow()
    iHandleForm = GetActiveWindow()
    iNull = SetParent(iHandleForm, iHandleDoc)
    strName = ActiveDocument.FullName
   
   UserForm2.Show
   
End Sub

Any suggestions would be helpful.  Thank you in advance.

Signature

Steven G
"One Day at a Time"

> Check out the use of the system.privateprofilestring function.
>
[quoted text clipped - 24 lines]
> >
> > Thanks,
Doug Robbins - Word MVP - 28 Dec 2006 08:01 GMT
I am not sure from where you are trying to run your MakeBkup code, but
instead of doing that, if I wanted to record the information that was being
entered into a userform, I would use the Exit event of each control on the
form use the System.PrivateProfileString to write the data from that control
to a similarly named "key" in the text file.

I am not sure why you are going to the extremes that you are to grab the
current window.  Just use an AutoNew macro in the template to load the
userform.

I doubt that the following applies, but you might want to take a look at it.

"Making a UserForm show above a newly created Word 2000+ document" at:

http://www.word.mvps.org/FAQs/Userforms/KeepUserFmAboveDoc.htm

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

> Thanks Doug for the direction.  I however am still running into the same
> type
[quoted text clipped - 75 lines]
>> >
>> > Thanks,
Steven G - 29 Dec 2006 05:28 GMT
Thank you for your reply, I will check in the form exit events, and I will
revisit the autonew macro.  I'll let you know what I find.
Once again, thank you for all your help.
Signature

Steven G
"One Day at a Time"

> I am not sure from where you are trying to run your MakeBkup code, but
> instead of doing that, if I wanted to record the information that was being
[quoted text clipped - 91 lines]
> >> >
> >> > Thanks,

Rate this thread:






 
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.