Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • Last Modified:

Word Userform and ini files to populate controls

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?


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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now