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.
LVL 1
TheDave1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sajuksCommented:
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
0
TheDave1Author Commented:
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!
0
NBrownohCommented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

TheDave1Author Commented:
Update:

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

Any ideas??
=
0
sajuksCommented:
try this
dim strDbName
dim objAccess
dim objDB
strDbName = server.MapPath("db/mydatabase.mdb")
Set objAccess = Server.CreateObject("Access.Application")
objAccess.Visible = False
objAccess.OpenCurrentDatabase strDbName
Set objDB = objAccess.CurrentDb()
objDB.DoCmd.OpenReport  "ReportName",acViewNormal
set objDB = nothing
objAccess.Quit acQuitSaveNone
Set objAccess = Nothing

Also chec k
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20113787.html for different options

I will be out for a few hrs will check back afterwards.Good luck
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TheDave1Author Commented:
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
0
sajuksCommented:
Glad you were able to get it working. Thanks for the points and grade
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.