Link to home
Start Free TrialLog in
Avatar of TheDave1
TheDave1

asked on

Printing an access report in a passworded DB

Hi guys,

Using VB, I'm trying to print a report on an Access database that is passworded.  Im
using DAO.  I can open the database, update etc.

Just when i try to print it creates a popup and asks for the database
password. I would like for the code to provide the password for automation...

This is the code im using.

Private Sub cmdPrint_Click()
PrintAccessReport App.Path & "\Database.mdb", "Results", False End Sub

Thanks in advance.
Avatar of sajuks
sajuks

Const dbPathName = "c:\Database.mdb"
Const strPassword = "thepassword"
Dim Acc As Object, db As Object

Set Acc = CreateObject("Access.Application")
Set db = Acc.Application.DBEngine.Workspaces(0).OpenDatabase(dbPathName, 0, False, ";pwd=" & strPassword)
Acc.OpenCurrentDatabase dbPathName, False
Set db = Nothing
Acc.DoCmd.OpenReport "ReportName", acPreview
Set Acc = Nothing
Avatar of TheDave1

ASKER

Thanks for the quick response.

I tried this, but nothing happens when I click on the Print button now :/

I left ReportName alone the first time and it spat an error back, so I know that it's along the right track... It just doesn't do anything at all with the right ReportName in there.

Also, rather than simply opening the report I would like it to either just print the report, or open/print..

Hope this makes sense!
this isnt related to the question but its a good practice, this will ensure that your path will always be a correct path.  If your program is installed on the root of a drive it allready has \ (ex. c:\) at the end of the string, if not there is no \ (ex c:\program files\your program) at the end.

Dim tPath As String

If Mid(App.Path, Len(App.Path), 1) = "\" Then
    tPath = App.Path & "Database.mdb"
Else
    tPath = App.Path & "\Database.mdb"
End If
Update:

When I said nothing happens, it actually does open an MSACCESS.EXE process that sits there and does nothing at all..

Any ideas??
=
ASKER CERTIFIED SOLUTION
Avatar of sajuks
sajuks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I actually ended up fixing this problem using the sendkeys function. Thanks to sajuks for trying his best, though. I have given him the points as he helped the most.

Cheers
Glad you were able to get it working. Thanks for the points and grade