|
-
Sep 14th, 2005, 11:34 AM
#1
Thread Starter
New Member
CSV to access with vba
Hi,
could you help me please.
I have csv file:
#text1.1=#text2.1 !text3.1
#text1.2=#text2.2 !text3.2
...
I need fill this csv onto access table with vba:
table:
----------------------------------------------------
| ID(automatic) | all row | text1.x | text2.x | text3.x |
----------------------------------------------------
Could you help me with vba, please (beginner)
-
Sep 14th, 2005, 11:38 AM
#2
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 14th, 2005, 11:56 AM
#3
Frenzied Member
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.
Tengo mas preguntas que contestas
-
Sep 14th, 2005, 12:02 PM
#4
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 14th, 2005, 02:58 PM
#5
Thread Starter
New Member
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.
-
Sep 14th, 2005, 03:12 PM
#6
Re: CSV to access with vba
You can parse out the data using Instr and Mid$
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 14th, 2005, 04:01 PM
#7
Thread Starter
New Member
Re: CSV to access with vba
and how save data into table (beginner)?
-
Sep 14th, 2005, 04:03 PM
#8
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 14th, 2005, 06:44 PM
#9
Frenzied Member
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.
Tengo mas preguntas que contestas
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|