I need to write a short vb program which will look up my c:\customer directory and send select csv files by email to my customer.
My directory c:\customer has multiple csv files all csv files have different names. Each csv file has a name and this name is unique to the customer. eg. If the file name = 123.csv then i need to email these files to a customer number 1.
ie each customer has a corresponding unique number which identifies them.
When the program reads through my directory and finds multiple CSV files named 123.csv then these multiple csv files need to be sent via email to customer 1.
If csv file is named 456.csv then these csv files need to be sent via email to customer 2.
I be told i need to create a text file which contains a list of unique codes with their corresponding customer email addresses.
Create the text file manually. Once that is done, go onto the next steps.
Create a VB program that reads in the text file and stores the information in an array.
Use a loop to step through the array.
For each line of the array, create a mail message.
Also use the DIR function to get a list of files from the directory for that customer. Add each of these files to the e-mail message as an attachment.
Send the mail message.
OR do the loop the other way around:
Use the DIR function to step through all files in the folder. For each file get the filename and use this to get the customers name and e-mail address from the array. Create the mail message, add the attachment and send the message.
wow! that was a fast! you guys are so fast at responding, it's great!..
I've created my text file, the location of the csv files will always be c:\customer.
Can you provide me with example syntax as to how the array is done.
I have already got the correct syntax for auto emailing. i just need help with reading from the directory & referring to the text file - before i email...
martinliss.. i need vb code which will look up c:\customer & select particular csv files from that directory based on their name, then email to relevant people.
eg.
If c:\customer contains 123.csv then i need to grab these files and email only 123.csv files to customer 1.
If 456.csv exists then i need to grab these files & email to customer 2.
My text file will act as a look up - which customer to send which files to...
All code must be in a Sub or Function and the error you are getting indicates that you have not done that. All the code from Dim nfile As Integer on down needs to be in a sub or function.
Originally posted by gilly salvelinus, my mistake - i have a file called 123T.csv and 123D.csv - i need to email both of these files. ...both need to be sent to same customer.
Then you may need to use something like Left() or Instr() to get only the matching part of the filename, i.e. "123", or use a wildcard. This might be simpler for you if you used a db instead of .csv files, but maybe that's not an option here.
ober5861 will Private sub form_load() work at the top of your code? ive tried it, but it keeps telling me that ive got a compile error "invalid outside proc".
It will not allow me to write private sub... after your dim xxx as string, or before the dim part....
The other stuff should (UDT definition and declaration of the UDT array) should be above all of that. Also, put "Option Explicit" as the very first line of your form module.
OK, here's a small demo on how to use classes in this sort of situation.
Alas, my code isn't as commented as well as Martins, I don't deserve god status
My code also has a SAVE function in the class Customers, and an ADD function. This allows you to add more customers at run time and then save them back to the file, thought this may be handy for you.
Some people may say that using class modules for this is overkill. But I am not a fan of large arrays of UDTs as if later down the line you have to change something then you can be pretty stuck and a rewrite is required. Class modules are slightly slower, but you won't see the difference, and they take up a little bit more resources. BUT on a plus they can have much more functionality as you can add code inside the class itself, like the Load and Save functions. This means that the code in your forms is kept to a minimum and is easier to read.
This is what classes were designed for, as well as other things, and really do help your application.
Watch, everyone will disagree with me now
Hope this helps.
Woka
Last edited by Wokawidget; Nov 21st, 2003 at 03:57 AM.
The code assumes that the lines that you are reading have at least three parts, each separated by a comma. That assumption was made because it looked like you were trying to get three pieces of information from each line.
I just need to figure out how to email each file depending on the customer. I get an error using the code below ..." failure on opening attachment" runtime error 32012" and it stops at .send. dont think it like *.csv
This line is good:
.AttachmentPathName = sFolderPath & "\*.csv"
BUT the * is no good.
Make sure sFolderPath does not end in a "\", as you are adding another one.
Make sure the * is replaced with the actual name of the file you are adding. Using DIR is a good approach to get the actual filename and to make sure the file actually exists.
And if you want to attach multiple files, you will need to do more work. The .AttachmentPosition needs to be changed for each attachment.