Link to home
Start Free TrialLog in
Avatar of codydoyle
codydoyle

asked on

Word Userform and ini files to populate controls

Hello,
I am wanting to use the following code that I got from https://www.experts-exchange.com/questions/20831550/Retaining-the-information-in-a-Userform.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?

Thanks

ASKER CERTIFIED SOLUTION
Avatar of MacNuttin
MacNuttin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial