Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

(80% Discount Ends Soon!)

Import Data from Access to Excel










Hi!,,, this is my situation. I have a user level password protected Access
Database and an Excel spreadsheet in which I need to load a query from the DB.
I am following these steps in excel: Data - Import External Data - Import
Data. But when I select the .mdb I want to import data from, and I fill the
fields user name and password, this happen with two different scenarios:

1- If the test connection button is pressed, the error message is "Test
connection failed because of an error in initializing provider. Cannot start
your application. The workgroup information file is missing or opened
exlucsively by another user." Well, I have a workgroup file, but don't know
how to load it during the import process.

2- If I simply press Ok, a second window appears with the legend "Please
enter MS JET OLE DB Initialization Information", I leave the fields with the
default data (the field "Provider String" is blank by defult) and press Ok,
then nothing happens, nor error message nor data imported.

If somebody has a suggestion, it would be highly appreciated!



I am trying to set up gradebooks for school teachers. I have an Access
parameter query that returns the students in a particular class when the user
enters the class name. I would like to use that query to insert the student
names in an Excel template. I have found multiple examples of how to import
data from Access if I am willing to use a blank database, but I need to
import to a template set up to keep track of grades and absences.

Thank you!



I have a CSV file and I wish to cretae a pivot table out of this.
I have written a macro to import this csv to access and then another
macro to create pivot.

My problem is that I run first macro from access and second from excel.

Is it possible to create a VBA code which will ask me name of the
access databse , location of the CSV file and the name of the excel
work book and do the all three task by using above macros?

A code example will be a great help.

How can I rename or change the labels on my pivot using VBA so that
code goes in my second macro .




Hello,
I used the macro published but the added recordset will show only if I close and reopen the Access database.
Is it possible (and how) to show immediately the added recordset?

Thanks a lot in advance.



Hello

I'd like to be able to press a button on an Excel sheet and start the process of
running the MSQUERY function. I tried just recording keystrokes as a macro,
clicking the following while in record mode:

Data/Import External Data/New Database Query/MS Access Database/Clicked on
Database Name

But nothing got recorded, it didn't work. I'm trying to save myself all those
keystrokes by automating the task right up to the point in the query where I
select which record I to import from the Access file.

I know enough about macros and VB to create a button and launch the macro, but
I'm really new at this. Does anyone have any code that can do a query from
Excel in an access file, pulling out a record of their choice?

Thanks

Harry





I have tried to import some data from Access to Excel and the text in the larger fields are being cut off. How do I fix this?


Greetings,

I would like to import multiple tables (simultaneously) from an Access database. I currently use Windows 2003, and I apologize if this questions has already been addressed in another post.

Any help would be greatly appreciated!

I have little code knowledge, by the way.

Regards,

Tommy


Hi,

Can I get Excel to access Outlook and scan for mails with specific headers or from a specific sender and copy them?

I have a program that does a similar thing, I thought if I decompile it I could use some of its code but it may be a bit over-engineered for what I'm trying to do.

I know there are links to start Outlook and create an e-mail and so on, but can Excel scan for mails within Outlook?

Thanks,
D


I have a routine that imports Excel data into an access form. It works great when the data is located in Cells. I decided to explor using comboboxes in excel to allow users to select data, and am not having a hard time importing that data into my access form. This is the typical code I use to import the data

frm.txtTargetRotationRate = XlSheet.Range("TargetRotationRate")

When I try the same thing using the combobox, I get an error saying thet the control does not exist...but it does (have checked everything multiple times)

frm.txtFilmTime = XlSheet.cmpFilmPersistency

How do I refer to the Excel combobox and the data within it?


How can I automate importing some files from Excel into Access.

The TransferSpreadsheet Macro Action doesn't allow me to select the range for some reason.

In Tables New - Import Table works perfectly

How can I automate this way of importing Tables to import 200 tables directly from Excel.

I found this

http://www.databasedev.co.uk/text-import-macro.html

which looks ideal but I can't see a way to save it when I Import Excel (no Advanced tab).

Any ideas? I'm sure I'm missing something obvious.


Hi, I need some VBA code to import a table from one access database to another access database. Is this even possible using VBA? I already have code to bring data from access to excel and vise versa. Thanks!


I'm not quite sure how to do this. I have a MS access table with many columns. I also have data from excel that will always have the same header names as the access table, but not all of them will match. For example: my Access table will have Column 1,2,3,4 but my excel table will only have a Column 2 and 4. How do I have Excel match the header name with access and import the data into those columns only? Is this possible? Any help you can provide would be great.


Hi,

I would like to ask, if anybody knows a vba code which will enable me to import data from Excel file to Access Database? I need to import only selected named range and paste data in existing table in Access (to the first empty line). I know how to do it while using Import Spreadsheet Wizard but l need to automate this process. Could anybody help me with my issue??

Thanks a lot,

N.


Hello,

I have working code to copy the matching records of an Access table into an Excel worksheet, but now I am trying to modify this code so that I can select a couple of specific fields from the table instead of just copying all of the fields (there are 15 fields in the table, but I only actually need 4 of them for this particular report).

Here is the code I am currently using to copy all of the fields over with the matching records:

Code:

Const myDB = "DSD Errors DB tester.mdb"
Private Sub CommandButton4_Click()
  ' Test Field Select button
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim sSQL As String
    
    sSQL = "SELECT * FROM DSD_Invoice_Requests WHERE `Paid?` IS NULL"
    
    Range("A2:O65536").ClearContents
    Application.EnableEvents = False

  ' Create the database connection
    Set cnn = New ADODB.Connection
    myFile = ThisWorkbook.Path & "\" & myDB
    
    With cnn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .Open myFile
    End With
    
  ' Create the recordset
    Set rst = New ADODB.Recordset
    rst.CursorLocation = adUseServer
    rst.Open Source:=sSQL, ActiveConnection:=cnn, _
        CursorType:=adOpenForwardOnly, LockType:=adLockOptimistic, Options:=adCmdText
    
  ' Transfer data to Excel
    Range("A2").CopyFromRecordset rst
    
  ' Close the connection and clean up references
    rst.Close
    cnn.Close
    Set rst = Nothing
    Set cnn = Nothing
    
    Application.EnableEvents = True
    myRow = Range("A65536").End(xlUp).Row - 1
    MsgBox ("Finished loading " & myRow & " record(s)."), vbInformation, "Data Loaded"
End Sub


How can I modify this so that I put specific fields from the table into columns in Excel that will not line up with the layout of the table? For the sake of the example, let's say that I need fields 2, 4, 6, and 8 of the table to go into columns 1, 2, 3, and 4 in Excel.

Thanks in advance for any help with this.


I have this huge data set in Excel (> 1000 rows and 25 columns) and i need to enter the data into Access. The reason I can't simply import it is b/c the data comes from multiple users with mulieple data sets every day.

I know how to enter it into an array and loop through it to enter access, but is there a way to import or "dump" the array into an Access database? What would be the best way to enter in a large data set into Access? Thanks in advance!


Hello,

I'm trying to import a query from Access into Excel (linked). I've performed this operation with other queries in my database, but I'm having trouble with one. Every time I import it, only the header rows display, no data. Any idea on what the problem is?

Thanks,
Jay


my goal is to write code to import a statically named file to a tabel. i've tried usign the docmd.transfer text.

is this possible? I am getting an error with the txt header not matching my pre define field names.

here's my coding:

DoCmd.TransferText acImportDelim, , "RMT_Trns_UPLOAD", strFullTxtPath & "RMT_TXNS_CURRENT.txt", True

more on the error:
if i open the .txt the the first row has YYYYMM and then data below ...this needs to import to the first field of the table.....then there is a space in the txt file to the second header Ethnic....this needs to improt tot he second field of the table.

NOTE: the field names in my table match those int he .txt.

thnaks
tuk


Hello,

I reference an object (Monarch) to create a table that I then want to import into my Access Database. The file is outputted by default to a .xls extension and Microsoft Excel 2.1 Worksheet (I am using Office 2003). When the below command runs, I receive an error indicating that the file is not in expected format. I have tried all the "TypeExcel#"'s and haven't had any luck. Any suggestions?

Code:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblVendBO", strExportTable, -1


I also tried to rename the file into a .tab file, however, when I import that file, it is all jibberish.

Thank you,
Roger


I've been using this site for ages, but this is my first post. I found several solutions that come close, but none that precisely answer my question below.

I am using the following code to import multiple files to Access using the TransferSpreadsheet code in a vba module. However, several of the files to import have multiple sheets (2, 3, or 8), and my code only imports the first worksheet in the workbook. I'd like to import all the data on each sheet into the same table in access, and all the worksheets have exactly the same format and column headers. I am thinking there must be a way to loop through the sheets, but it seems as though Access doesn't understand the same ws code that Excel does? Any advice is greatly appreciated!

Code:

Function Import_multi_SKfile()


Dim fs, fldr, fls, fl
Dim myPath As String

myPath = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\"))


Set fs = CreateObject("Scripting.FileSystemObject")
Set fldr = fs.getfolder(myPath & "UploadSKData\")
Set fls = fldr.files

For Each fl In fls
 
If Right(fl.Name, 4) = ".xls" Then
    'For Each ws In Worksheets - this is the code that creates the error
            DoCmd.TransferSpreadsheet acImport, , "tblSmartKeys", myPath & "UploadSKData\" & fl.Name, True
    'Next ws
End If
 
Next fl

End Function





is possible to import a csv to a table in access?

i have code that peorfrom the fcn from MS Excel to MS Access but i can't find info regarding CSV.

thanks
tuk


Hi All,

Im kind of looking for a way to automate (make it easyier) something that i have to do on a regular daily basis.

I have to import data from an Excel file(s) to a specific table in my database.

I would like to be able to do this through a command button within a form. So when i click on the button it would ask me to locate the excel file i would like to import and then copy only the Columns A and B data from the excel file to a table called tblTEST in my database automatically.

Is this easy enough to do? I have tried playing with some code but im not having any luck.

Can someone help me?

Regards
Sam


Does anyone know of an easy way to import other than the manual way of file-get external data-import.

I would like to be able to set something up that has a file location saved and when a new file is put in that directory I can just click a button and pull it into Access.

Thanks!


I am using the following:

Sub GetQueryDef()
'This sub will get data from an Existing QueryDef in my
'database and place the data on sheet1.

Dim db As Database
Dim Qd As QueryDef
Dim rs As Recordset
Dim Ws As Object
Dim i As Integer
Dim Path As String

'Set the Path to the database. This line is useful because
'if your database is in another location, you just need to change
'it here and the Path Variable will be used throughout the code.
'

Path = "G:\London\Home Depot\Common\Jose Guido\CreditAppTrack 11-21-06 Original DO NOT USE.mdb"

'Set Ws
Set Ws = Sheets("SameDayDecision")

'This set of code will activate Sheet1 and clear any existing data.
'After clearing the data, it will select cell A8.
Ws.Activate
Range("A8").Activate
Selection.CurrentRegion.Select
Selection.ClearContents
Range("A8").Select

'Set the Database and QueryDef. This QueryDef exists in the
'database.
Set db = Workspaces(0).OpenDatabase(Path, True, False)
Set Qd = db.QueryDefs("qry_Ops_SameDayDeci")
'Create a new Recordset from the Query based on the stored
'QueryDef.
Set rs = Qd.OpenRecordset()

'This loop will collect the field names and place them in the first
'row starting at "A8."
For i = 0 To rs.Fields.Count - 1
Ws.Cells(1, i + 1).Value = rs.Fields(i).Name
Next

'This line simply sets the font to bold for the headers.
Ws.Range(Ws.Cells(1, 1), Ws.Cells(1, rs.Fields.Count)).Font.Bold _
= True

'The next line will get the data from the recordset and copy it
'into the Worksheet (Sheet1).

Ws.Range("A9").CopyFromRecordset rs

'This next code set will just select the data region and auto-fit
'the columns
Sheets("SameDayDecision").Select
Range("A8").Select
Selection.CurrentRegion.Select
Selection.Columns.AutoFit
Range("A8").Select

Qd.Close
rs.Close
db.Close

End Sub

However, I keep getting runtime error

"Error 3061, too few parameters. Expected 2."

The debugger is stopping at

Set rs = Qd.OpenRecordset()

Am I missing something when defining

db.QueryDefs("qry_Ops_SameDayDeci")

?

Please help!

Thanks.

Jose




Hi

I have an access database, where I import some text files (by saving excel worksheet as txt) to Predefined tables in Access. Some queries are then run, which use these tables. I need to automate this process.

So what I basically need to do is, use an excel macro, which makes the Access Db to import the text file to a table and then run the access queries.

I am completely new to Access database and have no idea where to begin. I am not aware if exporting excel worksheets instead of text files will work as I have no backend knowledge of the database. I have basic knowledge of Excel VBA.

Any help will be greatly appreciated!!

TIA



Hi everyone hope there is someone who can help me.
I have a user form and a password protected ms access database..the access is my database and i want to import the data from it and place those data to an excel sheet...i have a code for that and it works perfectly...but my problem is the password in the database is not constant and it will be change every month what i want to do is i want to make a user form that has a TEXT BOX for password to be supply and a command button to execute the import and read the password supply in the TEXT BOX....hope you can help me for these Ive been looking in the internet for the possible answer but sad to say there is no same problem that being answer. thanks..