Excel VBA to Extract Data from an Access Database

  Рет қаралды 76,833

Access Jitsu

Access Jitsu

Күн бұрын

Пікірлер: 52
@kevinmould6979
@kevinmould6979 2 жыл бұрын
I'm a bit late to the game but this tutorial looks invaluable to me. I have a fairly complex set of data in an Access database that I need to provide to colleagues that don't have access to the database in Excel format so that they can then build their reports and presentations. I do this alongside my 'day job' which is a maintenance engineer so this video is priceless.
@kolavithonduraski5031
@kolavithonduraski5031 Жыл бұрын
same to me... everything you need to know for pulling data from access... 😊👍 its awesome
@aeththeband
@aeththeband 5 жыл бұрын
Pure EXCEL-lence. Spent hours trying to find help on this before I came across your video. Your method is the only method I found that has worked so far and it was super easy to implement. THANK YOU SO MUCH.
@F_XVII
@F_XVII 7 жыл бұрын
This video is such a great tool to use. The code you provided worked great. Instead of SQL I used the code to grab the entire database without qrys. Thank you very much!
@rodmaxwell8182
@rodmaxwell8182 3 жыл бұрын
Keep it simple - right!!... Excellent tutorial, just what I needed, thanks a lot!!!
@kolutimehin
@kolutimehin 8 жыл бұрын
This is a very skillful method. Kudos
@jonrasmussen5645
@jonrasmussen5645 3 жыл бұрын
Awesome job explaining everything. Thank you!
@giegoar
@giegoar 7 жыл бұрын
Works great expect when you use the pivot table, you can't refresh it "RefreshData - UpdateData VBA error: 1004 = We can't change this part of the PivotTable". Any suggestions? Many thanks!
@rangiroa100
@rangiroa100 Жыл бұрын
Hi Access Jitsu. Is there a way to obtain the VBA code text in a file ? Or you could post the VBA code here. It is really hard to just type them up because the text is so small.
@gregorywilson3715
@gregorywilson3715 2 жыл бұрын
Help! I want to import from access a query into a excel file, to a specific tab and cell
@georgestenning904
@georgestenning904 4 жыл бұрын
How do you get the headers to be transferred across as well?
@ashishsuryawanshi5871
@ashishsuryawanshi5871 4 жыл бұрын
Hi Thank you, But it is not working in the server location where only read access is there as I'm only reading the data.
@riadbaziz6930
@riadbaziz6930 4 жыл бұрын
Thank you a lot for this tutorial! At 08:29 how can I Open Database who has a password?
@prathabshivang6896
@prathabshivang6896 4 жыл бұрын
how to create invoice in excel from access database form ????? using vba or macros
@nithiyashreeg7507
@nithiyashreeg7507 4 жыл бұрын
Hi, Great work. I'm getting "VBA error : unrecognised database format " May I please know how to fix this error?
@EarendilTheBlessed
@EarendilTheBlessed 8 жыл бұрын
Thank you for this great tutorial!
@lukefreeman828
@lukefreeman828 3 жыл бұрын
oh man... this was brilliant but something incredibly simple would have made it so much more informative for people trying to learn; show us the Access Database you were pulling information from. I have my own .accdb and it would be so easy to know what I need to change if you'd shown us what your original database looked like lol. I also found it kinda weird that you told us a really basic thing like how to make sure dev mode was on and open vba editor etc, but rapidly dropped supporting that basic level of understanding and skipped straight to some seemingly advanced stuff - like what the hell all the SQL stuff was actually doing (this is where seeing the db would have been useful) :( Other than that, really useful video! :D
@t00by00zer
@t00by00zer 2 жыл бұрын
He gave two other examples of code that didn't require the SQL. And they're very easy to use. You can simply copy the entire recordset into an array, do your VBA searches in the array instead of using SQL Here's how I used his code: Public Const dbPath = "C:\Users\yourname\Excel Database Example\YourDB.accdb" Public db As DAO.Database Public rs As DAO.Recordset Sub test() RefreshData ("YourAccessTable") End Sub Sub RefreshData(tbl As String) On Error GoTo err Dim a As Variant, i As Long, j As Integer Application.StatusBar = "Connecting to the Database" Application.Cursor = xlWait Set db = OpenDatabase(dbPath) Set rs = db.OpenRecordset(tbl, dbOpenSnapshot) With rs .MoveLast .MoveFirst ReDim a(1 To rs.RecordCount, 1 To rs.Fields.Count) For i = 1 To .RecordCount For j = 0 To .Fields.Count - 1 a(i, j + 1) = .Fields(j).Value Next j .MoveNext Next i End With etc. The array "a" contains the entire recordset and is easily perused using VBA code for any relationships you want. I chose to use 1 as the starting index so that the array could easily be copied to a range or table.
@josepyoga3790
@josepyoga3790 7 жыл бұрын
How is writing the script for the Subtotal goods purchased and goods sold. As well as the visible remaining stock. Thank you
@FreeHappiness
@FreeHappiness Жыл бұрын
Can somebody please direct me to the code as the link is not showing the code.
@jillianwilms
@jillianwilms 3 жыл бұрын
very helpful!! Thanks!
@thomasvenus1129
@thomasvenus1129 5 жыл бұрын
Works perfectly. Thank you!
@apbosh1
@apbosh1 4 жыл бұрын
This was so helpful Thank you!
@Griffinbest
@Griffinbest 6 жыл бұрын
This is an amazing tutorial! Thanks so much
@manishsinha7452
@manishsinha7452 5 жыл бұрын
hi if in access database few data in( tabel1) saved with SAME NAME James but the address is different , I wand to pull the last saved james data not the first , plese suggest the code
@lebeluet
@lebeluet 8 жыл бұрын
Hi at 5m40s you mention do not use the DAO ref when you are on Excel but use the Microsoft Office xx.x library. Can you elaborate your point of view if the issue is not only releated on the code sample ?
@Accessjitsu
@Accessjitsu 8 жыл бұрын
I don't know why I said that now. Looking on the MS website, it looks like the DAO ref would work also. I have not tried it.
@janezklun
@janezklun 8 жыл бұрын
Great tutorial, thank you
@JeremyFisher
@JeremyFisher 7 жыл бұрын
I want open a PDF file using hyperlink , and i want to specify the file name by a cell value , can you help me please ?
@Thanogr1
@Thanogr1 5 жыл бұрын
Great, It shows me object 438 Object Error. As reference i use also DAO object librady
@johndavy3820
@johndavy3820 5 жыл бұрын
Great video. Thanks
@noelrobles960
@noelrobles960 6 жыл бұрын
Im so gonna try this at work, thanks
@rickl2834
@rickl2834 8 жыл бұрын
I am currently working on a project where I use VB code in access to do a query and have the SQL variable in a listbox, where I can see all the where conditions on my search. I then want to take that data and export it to an excel spreadsheet. :DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "QueryName", _ "C:\Users\My Computer\Desktop\TRUSTED\Project\Results.xlsx" works fine but I DON'T HAVE A DEFINATIVE QUERY, I HAVE AN SQL VARIABLE. The SQL = "Select...". I want to know how to transferspreadsheet to my desktop with the SQL Varable... is there a way or is there another option?
@Accessjitsu
@Accessjitsu 8 жыл бұрын
+Rick L Rick, I don't entirely understand your question. Do you mean you don't have a query that is saved as a database object with your specific criteria saved in it, you only have that in a string variable?
@rickl2834
@rickl2834 8 жыл бұрын
+Access Jitsu I figured out how to do a search using a query that would still show records despite the input being null. Now that I have a query, I can export to excel
@NimishP
@NimishP 4 жыл бұрын
How do you open database having password say "ASDF"
@waqqarahad8762
@waqqarahad8762 6 жыл бұрын
Nice work, kindly improve the quality of voice
@spawnyuk
@spawnyuk 7 жыл бұрын
Hi, awesome tutorial, can this code be modified to connect to multiple tables and put the data into the respective worksheet? I have around 24 tables with data that on a single click i want to go into its own Worksheet
@Accessjitsu
@Accessjitsu 7 жыл бұрын
Yes! In RefreshData, after executing the query I have there, then you could set the SQL string to a new query and execute it with "Set rs = db.OpenRecordset(SQL, dbOpenSnapshot)" and then loop through rs again putting that data wherever you want it. You could do that as many times as you want.
@spawnyuk
@spawnyuk 7 жыл бұрын
Sorry excuse my ignorance, i'm picking VBA up as i go along so trying to understand this all. Do i create a new SQL string (to store the SQL query) and what else? I have two tables at the moment: tblMasterData (my main source of data) (data goes into tblMasterData worksheet) tblPhase_Stages (lookup column data) (data goes into tblPhase_Stages worksheet) I can inject tblMasterData fine using your technique, but if i want to look at the Phase Stages table, where do i put the xlSheet reference so it goes into the respective worksheet? Currently i have: Set xlSheet = xlBook.Worksheets("tblMasterData") Then it clears the sheet: xlSheet.Range("A2:H1500").ClearContents Then i run my SQL statement: SQL = "SELECT * FROM tblMasterData" Then open my recordset Set rs = db.OpenRecordSet("tblMasterData", dbOpenSnapshot) Then copies to excel: xlSheet.Range("A2").CopyFromRecordSet rs But where do i add in the references to my other table? (tblPhase_Stages) *Just as an FYI, i have around 30 tables in my database, only 24 of those need to be exported to Excel as part of this VBA. The data is being exported into a 'Template' file which they will use to prep data for the re-upload into Access.
@Accessjitsu
@Accessjitsu 7 жыл бұрын
Since your openrecordset method is using the table name, you don't need "SQL". After you have written tblMasterData, do this: "Set rs = db.OpenRecordSet("tblPhase_Stages", dbOpenSnapshot)". This replaces the content of rs. Then "Set xlSheet = xlBook.Worksheets("tblPhase_Stages")" I don't know how you are naming your spreadsheet sheets, but you can also use an index to refer to the sheets in the workbook.
@spawnyuk
@spawnyuk 7 жыл бұрын
I've just cracked it, my code could become quite long and maybe isnt the most effective way to do it? ......To check, is the below the best way to execute what i want without any unneeded code? For each table in access, i need to: Set the DAO.Recordset: Dim rs As DAO.Recordset (query for tblMasterData) Dim rs1 As DAO.Recordset (query for tblPhase_Stages) Reference the worksheets: Dim xlSheet = xlBook.Worksheets("tblMasterData") Dim xlSheet2 = xlBook.Worksheets("tblPhase_Stages") Then set the reference to the worksheets: Set xlSheet = xlBook.Worksheets("tblMasterData") Set xlSheet2 = xlBook.Worksheets("tblPhase_Stages") Then clear the worksheets data is going into xlSheet.Range("A2:H1500").ClearContents xlSheet2.Range("A2:H1500").ClearContents Execute the query and populate recordset Set rs = db.OpenRecordset("tblMasterData", dlOpenSnapshot) Set rs1 = db.OpenRecordset("tblPhase_Stages", dlOpenSnapshot) Copy recordset to worksheets: xlSheet.Range("A2").CopyFromRecordset rs xlSheet2.Range("A2").CopyFromRecordset rs1 I also removed the reference to the SQL query as you mentioned, many thanks
@Accessjitsu
@Accessjitsu 7 жыл бұрын
That looks good. The only thing I would changes is your Dim statement for xlSheet(s): Dim xlsheet As Excel.Worksheet
@ontheroadagain5402
@ontheroadagain5402 8 жыл бұрын
After creating a button using the code provided, when I click on it to import the data, I get a compile error saying Dim db As DAO.Database is an unfound User-defined type. I have activated the MS Access resource in Excel prior to creating the button. I am using Excel 2013 trying to open an Access 2013 database. Any suggestions?
@Accessjitsu
@Accessjitsu 8 жыл бұрын
+Anne V. Tschider Yes, when you have the Visual Basic window visible, go to Tools>References and select "Microsoft DAO 3.6 Object Library", then OK.
@ontheroadagain5402
@ontheroadagain5402 8 жыл бұрын
+Access Jitsu Thank you. I just checked the 3.6 Object Library, but then I get "Error in loading DLL" after closing the references tool.
@Accessjitsu
@Accessjitsu 8 жыл бұрын
+Anne V. Tschider Here is a discussion about your exact situation: www.tek-tips.com/viewthread.cfm?qid=1731794
@atuainterlagos8958
@atuainterlagos8958 7 жыл бұрын
whats books example ?
How To Import An Excel Spreadsheet With VBA In Access 2013 🎓
31:28
Programming Made EZ
Рет қаралды 126 М.
CONNECT EXCEL AND MS ACCESS USING EXCEL VBA MACROS
18:04
iTech Analytic Solutions
Рет қаралды 31 М.
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 275 #shorts
00:29
Wait… Maxim, did you just eat 8 BURGERS?!🍔😳| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 8 МЛН
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 21 МЛН
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 58 МЛН
Automated Export of Data from Microsoft Access to Excel with Just One Click
20:47
Computer Learning Zone
Рет қаралды 18 М.
Extract Data from One Sheet to Another Using Excel VBA
8:37
ExcelDemy
Рет қаралды 4,6 М.
How to use ADO and VBA to Read from Worksheets
12:15
Excel Macro Mastery
Рет қаралды 76 М.
How To Pull Data From Access Using VBA
18:10
Sigma Coding
Рет қаралды 9 М.
Access to Excel Data Import
11:55
TeachExcel
Рет қаралды 19 М.
Setup Access to Link to/Import from Excel Spreadsheets
13:29
Access Jitsu
Рет қаралды 18 М.
EASILY Make an Automated Data Entry Form in Excel
14:52
Kenji Explains
Рет қаралды 789 М.
How to Create and Modify QueryDefs Programmatically in your MS Access Database
12:03
Sean MacKenzie Data Engineering
Рет қаралды 4,8 М.
Moving Excel Data into Access with VBA
14:21
Dr. Gerard Verschuuren
Рет қаралды 72 М.
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 275 #shorts
00:29