kashif.special2005
Active Member
- Joined
- Oct 26, 2009
- Messages
- 443
Hi,
While, I am using Sub (fetch_data) to fetch data from Access database and paste into excel file but error message is showing that
Erro Message:- Run-time error '3343';
Unrecognized database format 'C:\Users\Kashif\Desktop\Access Database & File\Kashif.accdb'.
Code.
Public db As DAO.Database
Public dbpath As String
Public rs As DAO.Recordset
Public Sub connection()
On erro GoTo err:
'dbpath = ActiveWorkbook.Path + "\" + Sheets("criteria").Cells(2, 6)
dbpath = Sheets("criteria").Cells(4, 6)
'Full path is C:\Users\Kashif\Desktop\Access Database & File\Kashif.accdb
Set db = OpenDatabase(dbpath, ture, True)
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
Public Sub fetch_data()
Dim sql As String
Call connection
sql = "select * from Allocation"
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
Sheets("criteria").Cells(5, 1).CopyFromRecordset rs
rs.Close
End Sub
Please help.
Thanks,
Kashif.
While, I am using Sub (fetch_data) to fetch data from Access database and paste into excel file but error message is showing that
Erro Message:- Run-time error '3343';
Unrecognized database format 'C:\Users\Kashif\Desktop\Access Database & File\Kashif.accdb'.
Code.
Public db As DAO.Database
Public dbpath As String
Public rs As DAO.Recordset
Public Sub connection()
On erro GoTo err:
'dbpath = ActiveWorkbook.Path + "\" + Sheets("criteria").Cells(2, 6)
dbpath = Sheets("criteria").Cells(4, 6)
'Full path is C:\Users\Kashif\Desktop\Access Database & File\Kashif.accdb
Set db = OpenDatabase(dbpath, ture, True)
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
Public Sub fetch_data()
Dim sql As String
Call connection
sql = "select * from Allocation"
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
Sheets("criteria").Cells(5, 1).CopyFromRecordset rs
rs.Close
End Sub
Please help.
Thanks,
Kashif.