ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel Access Security Question (https://www.excelbanter.com/excel-programming/373395-excel-access-security-question.html)

Neily[_3_]

Excel Access Security Question
 
Hi,

I use the code below to query against an Access Database. I would like to
add a password to the database so that it can't be accessed unless you have
the password.

Would anyone know how I would add such a password to Access and how to adapt
the code below to use that password.

Thanks
Neil

Sub QueryAccessDatabase()

Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset


DatabaseLocation = Range("DatabaseLocation").Text
Set conn = New ADODB.Connection
With conn
.Provider = "Microsoft.JET.OLEDB.4.0"
.Open DatabaseLocation
End With


' Create a new Recordset Object.
Set rst = New ADODB.Recordset
With rst
' Connect this recordset to the previously opened connection.
.ActiveConnection = conn
.Open NSelect & NFrom & NWhere, conn,
adOpenDynamic,adLockBatchOptimistic
End With

'This line dictates where the results will be placed.
Sheets("Queries").Range(DestinationCell).CopyFromR ecordset rst

' Close the recordset.
Set rst = Nothing
' Close the Connection.
conn.Close

Robert Bruce[_2_]

Excel Access Security Question
 
Roedd <<Neily wedi ysgrifennu:

Hi,

I use the code below to query against an Access Database. I would
like to add a password to the database so that it can't be accessed
unless you have the password.

Would anyone know how I would add such a password to Access and how
to adapt the code below to use that password.

Thanks
Neil


In Access ToolsSecuritySet Database Password

In your code:

With conn
.Provider = "Microsoft.JET.OLEDB.4.0"
.Open DatabaseLocation, , "MyPassword"

End With

Rob




All times are GMT +1. The time now is 10:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com