Importing from a comma-delimited file

J

John E.

Sue,
Trying to run the listing 24.5 in your book. What I did is set up the
notepad file and custom contract form per Section 24.1.6, published the form
to the Contacts folder. Then with the custom form in Design Mode, I opened
Visual Basic with Pg. 2 showing in the custom form and pasted your listing
24.5 into the module. Then attempted to Run Sub/User Form to import the
comma-delimited file into the Project field added into the custom form. I
get the following run time error:
"Compiler Error: User defined type not defined" which debug points to line
#6 -
Dim fso As Scripting.FileSystemObject
Can you advise what I am doing wrong to get the data read into the Project?
 
S

Sue Mosher [MVP-Outlook]

Sounds like you didn't add a reference to the Scripting Runtime library, as described in Section 10.4

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John E.

That was part of problem. Set reference and created Macro button on Toolbar
to run the code. Code now runs and prompts for path to the file "Project".
but then when I open a Contact created by the custom form that includes a
"Project" field, the Project field is still empty???? Do I need to run the
Macro with the custom contact open? Do I need to make the Macro for only the
Contacts folder rather than the Toolbar?
 
S

Sue Mosher [MVP-Outlook]

Are you sure you created the field correctly in the form definition? Do you see it in the form design, in the User-defined Fields in This Item list? Did you create the csv file as instructed?
Do I need to run the
Macro with the custom contact open?

No, if you read the code, you'd see it has nothing to do with an open item.
Do I need to make the Macro for only the
Contacts folder rather than the Toolbar?

A macro isn't "for" a folder or "for" a toolbar. A macro simply runs whatever code is in it. You can always step through the code and use the debugging tools in the VBA environment to check variable values, property values, etc. as the code runs.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John E.

Did everything just as instructed in book to create the form and the Project
file. Only thing I see that differes is that Notepad automatically gives the
Project file a .txt file convention rather than Project.csv as you mention it
in your comments. Went back thru the creation process once more for both the
form and the Project file to make sure and it still doesn't populate the
Project.txt field when I run the Macro????????
 
S

Sue Mosher [MVP-Outlook]

There is no Project.txt field. There should be a field in the form design named Project. (Did you check the All Fields page as I asked? ANd, there is a file that you named Project.txt. The code doesn't care what you name it, only that each line have two text strings, separated by a comma.

Step through the code and follow the logic. Make sure you provide the full path to the file. Then tell us what happens as you step through the code.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John E.

Sue,
I think I found the problem by doing Watch breaks and monitoring what was
happening at the string level while stepping thru code. I discovered that
when responding to the "File to Import:" prompt, you have to type the path
and the full name "Project.txt", including the file extension .txt. I had
been typing the path and just the name Project. When you don't include the
file extention in response to the prompt, the If statement at line 15 doesn't
find FileExists and drops to the End If, thus bypassing all the code that
actually populates the Project contact. This is something that you might
want to do some input validation on in the code to make sure the user knows
to input the path, Project and file extension in response to the prompt.
Thanks for sticking with me thru this. I think I understand this code
listing well enough now to adapt it to what I need to do for our applicaton,
which is:
1) read a file consisting of 8 records of two fields each into a a list box
that is 2 x 8. 2) Would also like to adapt the code to read the 8 records of
two fields from 8 rows of 2 columns each from an Excel spreadsheet. Then the
user of our application can easily keep the list box data up to date by
modifying the spreadsheet periodically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top