Fetch Data From MS-Access

kashif.special2005

Active Member
Joined
Oct 26, 2009
Messages
443
Hi,

I have a student database in MS-Access, And I want to fetch some part of data from ms-access to excel.There is a macro in access where 20 to 25 queries in that macro, I want to hit macro first so macro will do all the calculation in ms-access, then at end final query will store result data in "Student_Final_Result" table, After that I want to fetch all data from "Student_Final_Result" to excel in Sheet("Student").range("a1"), But I am not sure how will I do this.....:confused:

Database Name Student_Data.mdb
Macro_Name Stu_Calc
Temprary_Table Student_Final_Result
Excel_Workbook Student Result
Result_Sheet Student
Paste_Range Sheet("Student").range("a1")

Please help me to resolve this problem.

Thanks & Regards,
Kashif.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Kashif

Kind of off topic, but what do these 25 queries actually do?

That sounds like a lot of queries just to get some calculations done and produce the results.
 
Upvote 0
Hi,
Thanks for reply......

These 25 queries actually doing unnecessary data deleting, updating, applying calculation fields, data appending like wise and at finally at last final data appending in a temporary table............

Thanks,
Kashif.
 
Upvote 0
Hi,

I am using below code for fetching the data from MS-Access to Excel, But I am not able to find solution that how can I run a macro in MS-Access through Excel VBA.

'Global Variable

Public db As DAO.Database
Public dbpath As String
Public rs As DAO.Recordset

'DB Connection Procedure

Public Sub connection()
On erro GoTo err:
dbpath = "C:\Users\Kashif\Desktop\Excel & Access Files\Access Database & File\Student_Data.mdb" 'Database path

Set db = OpenDatabase(dbpath, ture, True) 'Open Database
Exit Sub
err:
Select Case err.Number
Case 3024
MsgBox "Database not found. Please save the database at the location of current folder"
Application.Calculation = xlCalculationAutomatic
End
Case Else
End Select
End Sub

'Fetching the data from Access in Excel

Public Sub fetch_data()

Dim sql As String

Call connection 'Open Connection

'Here I want that after open connection first hit the macro "Stu_Calc", After that below code should run.

sql = "select * from Student_Final_Result" 'Fetching Query

Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
Sheets("Student").Cells(2, 1).CopyFromRecordset rs 'Pasting Data
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

End Sub

Please help.

Thanks,
Kashif.
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,424
Members
452,914
Latest member
echoix

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top