Hi guys, can someone help i am trying to do vba/access link for the first time, and its quite hard!
I am trying to access a report in access (which has a password) called R_UCITS-AIFM_Summary
via an excel VBA, my first issue is normally input two dates, start and end date (normally the same) then press run (in access) but i am trying to do it all through vba excel,
Can anyone kindly shed some light for me?
I keep getting Run time error,Automation error and unspecfied error rolled into one message which is how bad its all going!
here is my code so far
Sub getdatafromaccess()
Dim DBFullname As String
Dim Connect As String, Source As String
Dim Connection As ADODB.Connection
Dim Recorder As ADODB.Recordset
Dim Col As Integer
Dim pword As String
Cells.Clear
pword = "ABC"
DBFullname = "Z:\Portfolio Analysis\Exposure Monitoring\PAS_ACCESS.accdb"
Set Connection = New ADODB.Connection
Connect = "Provider=Microsoft.ACE.OLEDB.12.0;"
Connect = Connect & "Data source=" & DBFullname & ";" & "Jet OLEDB:Database Password" = pword
Connection.Open ConnectionString:=Connect
Set Recordset = New ADODB.Recordset
With Recordset
Source = "Select * from R_UCITS-AIFM_Summary"
.Open Source = Source, Connection, ActiveConnection:=Connection
For co = 0 To Recordset.Fields.Count - 1
Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name
Next
Range("A1").Offset(1, 0).CopyFromRecordset Recordset
End With
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
End Sub
I am trying to access a report in access (which has a password) called R_UCITS-AIFM_Summary
via an excel VBA, my first issue is normally input two dates, start and end date (normally the same) then press run (in access) but i am trying to do it all through vba excel,
Can anyone kindly shed some light for me?
I keep getting Run time error,Automation error and unspecfied error rolled into one message which is how bad its all going!
here is my code so far
Sub getdatafromaccess()
Dim DBFullname As String
Dim Connect As String, Source As String
Dim Connection As ADODB.Connection
Dim Recorder As ADODB.Recordset
Dim Col As Integer
Dim pword As String
Cells.Clear
pword = "ABC"
DBFullname = "Z:\Portfolio Analysis\Exposure Monitoring\PAS_ACCESS.accdb"
Set Connection = New ADODB.Connection
Connect = "Provider=Microsoft.ACE.OLEDB.12.0;"
Connect = Connect & "Data source=" & DBFullname & ";" & "Jet OLEDB:Database Password" = pword
Connection.Open ConnectionString:=Connect
Set Recordset = New ADODB.Recordset
With Recordset
Source = "Select * from R_UCITS-AIFM_Summary"
.Open Source = Source, Connection, ActiveConnection:=Connection
For co = 0 To Recordset.Fields.Count - 1
Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name
Next
Range("A1").Offset(1, 0).CopyFromRecordset Recordset
End With
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
End Sub