help!!!!vb pgm to import data from access and copy to new excel sheet
hi give me codes of a vb pgm to import data from access database and copy it to new excel sheet.......
Search the web for tutorials for both ends of your request as there are many out there and probably some on this site. Then when you run across a specific problem come back and post as I doubt someone will spend their time doing your work for you.
'EXPORTS TABLE IN ACCESS DATABASE TO EXCEL
'REFERENCE TO DAO IS REQUIRED
Dim strExcelFile As String
Dim strWorksheet As String
Dim strDB As String
Dim strTable As String
Dim objDB As DataSet
'Change Based on your needs, or use
'as parameters to the sub
strExcelFile = "C:\My Documents\MySpreadSheet.xls"
strWorksheet = "WorkSheet1"
strDB = "C:\My Documents\company.mdb"
strTable = "MyTable"
objDB = OpenDatabase(strDB)
'If excel file already exists, you can delete it here
If Dir(strExcelFile) <> "" Then Kill(strExcelFile)
"SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
"].[" & strWorksheet & "] FROM " & "[" & strTable & "]")
objDB = Nothing
I have tried this code but its giving me error on "Opendatabase" is not declared
and "Error 2 'Execute' is not a member of 'System.Data.DataSet'.
so how to solve it
Well now we know that you are using VB.NET and this forum is for "classic" vb. See if you can PM a mod to have your thread moved.
FYI: This code is for .Net, not VB Classic
Code marked in Red needs to be changed to match your files, paths, and tables.
Public Class Form1
Private connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AccessProjects\Tests\db1.mdb;"
Private conn As OleDb.OleDbConnection
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
conn = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn = New OleDbConnection(connstring)
Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
Dim sSQL As String = String.Empty
Dim sExcelFile As String = "C:\VB.NetProjects\AccessToExcel\xltest.xls"
Dim sWorksheet As String = "tblTest"
Dim sTable As String = "tblTest"
'Delete old excel file if it exsists
If IO.File.Exists(sExcelFile) Then
sSQL = "SELECT * INTO [Excel 8.0;DATABASE=" & sExcelFile & "].[" & sWorksheet & "] FROM " & "[" & sTable & "]"
Dim command As New OleDbCommand(sSQL, conn)
Moved To .NET section
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
By Mike Mitchell in forum .NET
Last Post: 09-13-2002, 06:41 PM
By Michelle in forum VB Classic
Last Post: 04-19-2002, 06:01 PM
By David Jones in forum Database
Last Post: 08-31-2001, 01:22 PM
By Tim A. in forum VB Classic
Last Post: 02-23-2001, 05:57 PM
By John Simmons in forum Enterprise
Last Post: 02-09-2001, 01:42 PM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL