Hi Tammy
I've managed to achieve this with 2 ini files but can't figure out how to do
it with just one
first of all I initialize the combo box from a file called userindex.ini
that looks a bit like this:
[1]
Index=1
Name=Jay
[2]
Index=2
Name=Tammy
with this code:
Public Sub UserForm_Initialize()
Dim i As Integer ' defines the integer it index
Dim sName As String ' defines the string to hold the name
' looks at up to 30 i's in userindex.ini and returns the Name field into
the combo box
For i = 1 To 30 ' for each i
' make sName = to the Name field
sName = System.PrivateProfileString("\\path\userindex.ini", i, "Name")
' and add it to the combo box list
cmbSelectName.AddItem sName
Next i
End Sub
then get the userdata from a userinfo.ini containing something like this:
[Jay]
Name=Jay
JobTitle=Junior Assistant Trainee Macro Writer
[email protected]
phone=01234 567 890
[Tammy]
Name=Tammy
JobTitle=Senoir Macro Guru
[email protected]
phone=09876 543 210
and returns it with this code:
Public Sub cmdOK_Click()
'code for OK button goes here
Dim sName As String ' defines the string to hold the name
Dim sJobTitle As String ' defined the string to hold the job
title
Dim sEmail As String ' defines the string to hold the email
Dim sPhone As String ' defines the string to hold the phone
' pulls the field from the userinfo.ini and holds it in the relivent
string
sName = System.PrivateProfileString("\\path\userinfo.ini",
cmbSelectName.Value, "Name")
sJobTitle = System.PrivateProfileString("\\path\userinfo.ini",
cmbSelectName.Value, "JobTitle")
sEmail = System.PrivateProfileString("\\path\userinfo.ini",
cmbSelectName.Value, "email")
sPhone = System.PrivateProfileString("\\path\userinfo.ini",
cmbSelectName.Value, "phone")
Selection.GoTo What:=wdGoToBookmark, Name:="name" ' goto the
bookmark
Selection.TypeText Text:=sName ' write the
contents of the string
Selection.GoTo What:=wdGoToBookmark, Name:="from" ' goto the
bookmark
Selection.TypeText Text:=sName ' write the
contents of the string
Selection.GoTo What:=wdGoToBookmark, Name:="job" ' goto the
bookmark
Selection.TypeText Text:=sJobTitle ' write
the contents of the string
Selection.GoTo What:=wdGoToBookmark, Name:="email" ' goto the
bookmark
Selection.TypeText Text:=sEmail ' write the
contents of the string
Selection.GoTo What:=wdGoToBookmark, Name:="phone" ' goto the
bookmark
Selection.TypeText Text:=sPhone ' write the
contents of the string
Selection.GoTo What:=wdGoToBookmark, Name:="home" ' goto home (top
of document)
Unload Me
End Sub
Because I don't want to edit the code each time I add or remove a user I've
used a For Loop to populate the combo box, but I can only do that if the
index is an integer (am I correct in thinking that?)
However, since I've got an integer as the index, I can't then use the same
ini file to get the userinfo because I'm returning it with combobox.value
which is the username not the index value
It works, as it stands, and I can write a macro that will ammend both files
at the same time, but it just seems that it's not a very elegent way of
achieving the result.
Any suggestions??? (anyone?)
Kind regards,
Jay
jay said:
thanks Tammy, very nice of you to offer.
I'm going to have a play arround now with it and see what I can come up
with, though your code will come very handy though. Please do feel free to
mail me directly.
I'll let you know how I get on
Regards,
Jay
http://support.microsoft.com/default.aspx?scid=kb;en-us;237436&Product=OFF2003 file
and I'm
looking users
name,