Re: CSV to access with vba
You can use the .TransferSpreadsheet method inside of Access to Import the sheet in one line of code. ;)
VB Code:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Table1", "C:\Test.xls", False
Re: CSV to access with vba
I don't think that'll work for him, from his example. No common delimiters, for one thing. It looks like he'll have to read it in and parse the string somehow.
Re: CSV to access with vba
Ah yes, I missed that. Then its not a Comma Separated Values file. ;)
I was going to add that in order todo csv into Access you would need to open the csv in excel programmaticalls and then save as a xls file. Then execute the transfer. ;)
Re: CSV to access with vba
csv for examle:
#a_string1=#a_string2 !a_string3 ...first row of csv(record of table)
#a_string1=#a_string2 !a_string3 ...second rowof csv(record of table)
...
I have in access this table:
my_table(
id automatic_number,
all_row text,
string1 text,
string2 text,
string3 text,
)
my_table.all = all row in csv
my_table.string1 = string between first "#" and first "="
my_table.string2 = string between second "#" and first " !"
my_table.string3 = string between first " !" and end of row(\n)
I'd like fill data from csv into my_table.
Re: CSV to access with vba
You can parse out the data using Instr and Mid$ ;)
Re: CSV to access with vba
and how save data into table (beginner)?
Re: CSV to access with vba
Easiest is to use ADO. Here is one of best tutorials on ADO and DBs. ;)
http://www.vbforums.com/showthread.php?t=81916
Re: CSV to access with vba
Just because you have a file with a .csv extension doesn't mean it's a csv file. csv stands for comma separated values. In that case, you data would look something like this:
VB Code:
#a_string1=, #a_string2, !a_string3
You can use something besides a comma as a delimiter - the pipe symbol is a common one - but at any rate, it has to be the same delimiter.
If you didn't want to strip out the #, =, and ! symbols, and you just wanted the individual values, you could import in one line of code.
As it is, you'll have to read each line in individually in a loop, strip out the parts you don't want, then do an update on your table. If there are a lot of records, that could take a while.