Accessing a secured Database from Excel

A

Annelie

I put this to the excel forum but now I am thinking that perhaps an access
guru is needed to answer this:
I am using Excel Vba to export a table from excel to access. Everything
works fine in an unsecured database.
What code would I have to insert to open a secured database?

Sub DAOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim db As Database, rs As Recordset, r As Long
Set db = OpenDatabase("C:\DATA\3c\PayrollData2.mdb")
' open the database
Set rs = db.OpenRecordset("TblHOURSBYDAY", dbOpenTable)
' get all records in a table
r = 2 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("Workdate") = Range("A" & r).Value
.Fields("EmplName") = Range("B" & r).Value
.Fields("Payroll Item") = Range("C" & r).Value
.Fields("Duration") = Range("d" & r).Value
.Fields("JobNumber") = Range("e" & r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub

Annelie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top