Word Userform and ini files to populate controls

Posted on 2005-03-16
Medium Priority
Last Modified: 2008-03-06
I am wanting to use the following code that I got from http://www.experts-exchange.com/Applications/MS_Office/Word/Q_20831550.html?query=Userforms+Word&clearTAFilter=true 

I have a word userform with many controls that will be used to enter data for many different patients and populate bookmarks in the new. I then want to save the updated values for each of the controls to an ini (AnswerFile) file named specifically for that patient.

What I want to happen is upon opening the template, a small userform will pop up asking me to browse to the appropriate ini file that contains the most recent answers for the specific patient I am working on. When I browse to the ini file and click ok, the form closes and the main userform opens with all the controls populated with the last values saved in the ini file. Upon closing the form, the user should be prompted weather or not to save the new values of the controls into the ini file.

Here is the code I copied from the above ee expert

Private Sub CommandButton1_Click()
Dim temp As String
Dim sDesigPath As String
Dim sIniFile As String

sDesigPath = Options.DefaultFilePath(Path:=wdUserTemplatesPath)
sIniFile = sDesigPath & "\Personal.ini"
System.PrivateProfileString(sIniFile, "Personal", "From") = frmFax.TextBox6
System.PrivateProfileString(sIniFile, "Personal", "Extension") = frmFax.TextBox7
System.PrivateProfileString(sIniFile, "Personal", "SenderID") = frmFax.TextBox8

1.      Am I on the right track with INI files or would saving the values to another format such as XML or in the document itself be more appropriate?
2.      How do I get the Values in and out of the user form? The last three lines of the above code and the temp variable have me stumped. From what I can tell the above code is assigning values to the text boxes in frmFax, but what does (sIniFile, “personal”, “From”) mean?  How do I save back into the ini file?
3.      How do I handle the text box to browse for the files for each name, ie  C:\PatientFiles\Doe,Jane\JaneDoeAnswerSheet.ini and if the file does not exist have it create a new ini file for that patient?


Question by:codydoyle
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 11

Accepted Solution

MacNuttin earned 2000 total points
ID: 13559609
1. Yes use this code to create an ini file with the last used form info

2. Temp has no meaning for the code that is shown can be removed

3. This code is for a document template (probably a fax form) that has a userform open with the template. The textbox's are in the userform. The textbox text is inserted to bookmarks in the document

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Curious about the latest ransomware attack? Check out our timeline of events surrounding the spread of this new virus along with tips on how to mitigate the damage.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question