-
Jul 23rd, 2018, 05:03 PM
#1
Thread Starter
Junior Member
Export Access database in Excel - OLEDB
hi to all again
i have another question.
how can i extract the tables from a database to Excel?
i search online but i found only code with DoCmd line
I dno't know why but when i insert that codeline the program not recognize that.
someone can help me with that how to import that command or know how to export the database to excel without using doCmd?
Thanks to all
-
Jul 23rd, 2018, 10:43 PM
#2
Re: Export Access database in Excel - OLEDB
Let's be clear on the language first. You've posted this in the VB.NET forum. I'm not 100% sure but I expect that DoCmd is a VBA thing. Do you definitely want a solution in VB.NET?
-
Jul 24th, 2018, 01:58 AM
#3
Re: Export Access database in Excel - OLEDB
Hi,
perhaps you mean with SQL ?
if so you need a valid connection with Database to execute the SQL
Code:
strSQL_Excel = "SELECT * INTO [mySheetName] In 'C:\data81.xls' 'EXCEL 9.0;' FROM myAccessTable"
the will Export the Table in Access = MyAccessTable
to a new ExcelWorkbook = data81.xls
and create the Sheet = mySheetName
with the Data from the Access Table
regards
Chris
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Jul 24th, 2018, 02:56 AM
#4
Thread Starter
Junior Member
Re: Export Access database in Excel - OLEDB
Originally Posted by jmcilhinney
Let's be clear on the language first. You've posted this in the VB.NET forum. I'm not 100% sure but I expect that DoCmd is a VBA thing. Do you definitely want a solution in VB.NET?
Yes
i do a windows application who connect to a local database in Access.
My database is not an sql database.
-
Jul 24th, 2018, 03:30 AM
#5
Re: Export Access database in Excel - OLEDB
SQL is not a kind of database, it is an (almost) standardised language for talking to databases, which can be used for databases created in Access and many other systems (including Oracle, Informix, and ones that happen to have SQL as part of their name, like SQL Server and MySQL). Instructions like "SELECT * FROM tablename" and "INSERT INTO tablename VALUES (...)" are examples of SQL statements.
The SQL statement ChrisE showed is designed to be run against an Access based database, and will export the data to Excel. Just set up an OLEDBConnection to the database, and an OLEDBCommand with CommandText set to what ChrisE showed (altering the table names etc as apt).
-
Jul 26th, 2018, 09:58 AM
#6
Re: Export Access database in Excel - OLEDB
Hello,
Check out the following MSDN code sample and be sure to read the comments which talk about possible issues and side affects.
Note there is a good deal of code involved in the above code sample yet at the core it's very simple (keeping in mind of side affects).
Code:
cmd.CommandText = $"SELECT {SelectStatement} INTO [{Provider}DATABASE={ExcelFileName};HDR=No].[{WorkSheetName}] FROM [{TableName}]"
Solution
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
|