Connect from one Secured Access DB to another, but different MDW f

K

K Bare

I've been looking, unsuccessfully, for VBA on how to connect from one mdw
secured database to another that has a different mdw file. Is this even
possible? I've found information to do this from VB, but not from VBA while
MS-Access is open with a different MDW file.

I just want to query data in another table that users have permissions to
read in another database.

Thanks,
- Kirk.
 
K

K Bare

Thanks Alex, That is what I had feared. I have no idea how to work with the
DLL process you suggest. If I do find out, you mention VB, will it work in
VBA?
 
C

Chris O'C via AccessMonster.com

Use privdbengine. Example:

Public Function testSecureDB() As Boolean
On Error GoTo Proc_Err

Dim worked As Boolean

worked = openSecureDB("c:\db\secure.MDW", _
"username", "mypass", "c:\db\emps.mdb")
Debug.Print worked

Exit Function
Proc_Err:
MsgBox Err.Number & vbCrLf & Err.Description
Err.Clear
End Function


Public Function openSecureDB(strPathToMDW As String, _
strUser As String, strPwd As String, _
strPathToDB As String) As Boolean
On Error GoTo Proc_Err

Dim dbp As PrivDBEngine
Dim wk As Workspace
Dim db As Database
Dim rs As DAO.Recordset

Set dbp = New PrivDBEngine
dbp.SystemDB = strPathToMDW
dbp.DefaultUser = strUser
dbp.DefaultPassword = strPwd
Set wk = dbp.Workspaces(0)
Set db = wk.OpenDatabase(strPathToDB)
Set rs = db.OpenRecordset("queryname")
Do While Not (rs.EOF)
Debug.Print rs!lastname
rs.MoveNext
Loop
openSecureDB = True
Proc_Exit:
Set rs = Nothing
Set db = Nothing
Set wk = Nothing
Set dbp = Nothing

Exit Function
Proc_Err:
MsgBox Err.Number & vbCrLf & Err.Description
Err.Clear
openSecureDB = False
Resume Proc_Exit
End Function


Chris
 
C

Chris O'C via AccessMonster.com

Sorry, forgot a line of code in the proc's exit.

Public Function openSecureDB(strPathToMDW As String, _
strUser As String, strPwd As String, _
strPathToDB As String) As Boolean
On Error GoTo Proc_Err

Dim dbp As PrivDBEngine
Dim wk As Workspace
Dim db As Database
Dim rs As DAO.Recordset

Set dbp = New PrivDBEngine
dbp.SystemDB = strPathToMDW
dbp.DefaultUser = strUser
dbp.DefaultPassword = strPwd
Set wk = dbp.Workspaces(0)
Set db = wk.OpenDatabase(strPathToDB)
Set rs = db.OpenRecordset("queryname")
Do While Not (rs.EOF)
Debug.Print rs!lastname
rs.MoveNext
Loop
openSecureDB = True
Proc_Exit:
rs.Close
Set rs = Nothing
Set db = Nothing
Set wk = Nothing
Set dbp = Nothing

Exit Function
Proc_Err:
MsgBox Err.Number & vbCrLf & Err.Description
Err.Clear
openSecureDB = False
Resume Proc_Exit
End Function


Chris
 

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