Hi,
I'm trying to open a database that has a password using VBA
this is my code but it doesn't seem to work, what am i doing wrong?
I'm trying to open a database that has a password using VBA
this is my code but it doesn't seem to work, what am i doing wrong?
Code:
Dim MyImp 'TB file name
Dim MyImpAdd 'TB file path
Dim FullAdd 'Full TB file name (inc path)
Dim vtSql$ 'SQL string used for the Access delete query
Dim db As Database 'Access Database
Dim rs As Recordset 'Used to loop through records in Access database
Dim r As Long 'Used to loop through cells in database
Dim Password As String 'Password needed to open database
'Full Access Database address
MyImp = ThisWorkbook.Worksheets("Start").Range("B8").Value
MyImpAdd = ThisWorkbook.Worksheets("Start").Range("F8").Value
FullAdd = MyImpAdd & MyImp
'Set Access Database name
Set db = OpenDatabase(FullAdd, "1nvpivotDB=" & Password)
'delete existing data in the database for this month
'create a Delete Query SQL string to do this
vtSql = ""
vtSql = vtSql & " DELETE ALL_DATA.*, ALL_DATA.Date "
vtSql = vtSql & " FROM ALL_DATA"
vtSql = vtSql & " WHERE (((ALL_DATA.Date)=#" & ThisWorkbook.Worksheets("Start").Range("G17").Value & "#))"
db.Execute vtSql