Link to home
Start Free TrialLog in
Avatar of ekohartono
ekohartono

asked on

Access Report w/ VB

  Dim acc As Access.Application
   Set acc = CreateObject("Access.Application")
   acc.OpenCurrentDatabase("c:\data.mdb")
   appAccess.DoCmd.OpenReport "Item Report, acPreview
   appAccess.Visible = True

This code work fine but if data.mdb have database password
this code have little bit problem. My question is how
to open report with database pass in it.

Thanks
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

use this:

Const dbPathName = "c:\database.mdb"
Const strPassword = "PASSWORD"
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 ekohartono
ekohartono

ASKER

Thanks Emoreau
Your Code Help Me
I still Have 1 Question I hope You Don't Mind To Help Me Again.
In Crystal Report We Can Design Filter Like Code at bottom

Crystalreport1.selectionformula="{item.code} like 'EL*' and {item.Date} = date(" & year(vardate) & ","
& month(vardate) & "," & day(vardate) & ")"


That WeCan Change In Run Time So We Can Arrange Report That We Need. Can We Do It In Access Report ?

Thank You

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

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
Thank's Lot
Can I Do Like This ?

Acc.DoCmd.OpenReport "ReportName",acPreview,, "="item.code like 'EL*'" and item.date like '02/02/02'"
date datatype are not working with the Like operator.

also dates must be enclosed between #
To Emoreau

There is away to open report without open MS Access ?
Because if I use DoCmd.OpenReport I will See A Report And if i Minimize Report Window I Can Choose Tables Object So Any One Can Change My Database.
My Question At
http://devx.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20276662


Thank You