Printing an Access report using late binding

T

TrussworksLeo

Hello,

I am having problems getting access to print using late binding. I am
specially
having problems with this line and the ObjectType property

oAccess.DoCmd.SelectObject(ObjectType:=oAccess.AcObjectType.acReport,
ObjectName:=Report, InDatabaseWindow:=True)

How do I tell it to use a access report with late binding?

Here is all the code:

Dim sDBPath As String 'path to Reports.Adp

Dim oAccess As Object
'oAccess = CreateObject("Access.Application")

' The path to Reports.Adp:
sDBPath = "C:\Alpine\Ais\Reports.adp"

' Open Reports.adp in shared mode:
oAccess.OpenCurrentDatabase(filepath:=sDBPath, Exclusive:=False)

' Select the report name in the database window and give focus
' to the database window:

oAccess.DoCmd.SelectObject(ObjectType:=oAccess.AcObjectType.acReport,
ObjectName:=Report, InDatabaseWindow:=True)

oAccess.DoCmd.OpenReport(ReportName:=Report,
View:=oAccess.AcView.acViewNormal)

Thank You, Leo
 
D

Dirk Goldgar

TrussworksLeo said:
Hello,

I am having problems getting access to print using late binding. I am
specially
having problems with this line and the ObjectType property

oAccess.DoCmd.SelectObject(ObjectType:=oAccess.AcObjectType.acReport,
ObjectName:=Report, InDatabaseWindow:=True)

How do I tell it to use a access report with late binding?

Here is all the code:

Dim sDBPath As String 'path to Reports.Adp

Dim oAccess As Object
'oAccess = CreateObject("Access.Application")

' The path to Reports.Adp:
sDBPath = "C:\Alpine\Ais\Reports.adp"

' Open Reports.adp in shared mode:
oAccess.OpenCurrentDatabase(filepath:=sDBPath,
Exclusive:=False)

' Select the report name in the database window and give focus
' to the database window:

oAccess.DoCmd.SelectObject(ObjectType:=oAccess.AcObjectType.acReport,
ObjectName:=Report, InDatabaseWindow:=True)

oAccess.DoCmd.OpenReport(ReportName:=Report,
View:=oAccess.AcView.acViewNormal)



1. With the line that sets oAccess commented out, as shown here:
'oAccess = CreateObject("Access.Application")

the code will surely fail, as you don't have an Access application object to
work with. Is that commented out for some temporary testing you were doing?

Is this VB.Net code? If it's VB or VBA, you have to use the Set statement
to set the object variable:

Set oAccess = CreateObject("Access.Application")

2. Why are you selecting the report with SelectObject? It shouldn't be
necessary, just to print the report. If you leave that out, we don't have
to worry about debugging that line.

3. Does the code compile with your reference to oAccess.AcView.acViewNormal?
I wouldn't expect it to, but maybe I'm mistaken. How about leaving that
out, and just writing:

oAccess.DoCmd.OpenReport ReportName:=Report
 
T

TrussworksLeo

Dirk,

Thank You for the response.

It is VB.Net and the line you recommended worked perfectly.

Thanks Again, Leo
 
T

TrussworksLeo

Dirk,


Sorry I am still missing somthing. How do I get the View to work correctly
with late binding?

It does not understand what acViewnormal means? I forgot to switch back to
late binding before running my last test.

Now that I am using late binding again it shows a dialog which I would like
to avoid.

Thanks, Leo
 
D

Dirk Goldgar

TrussworksLeo said:
Dirk,


Sorry I am still missing somthing. How do I get the View to work
correctly
with late binding?

It does not understand what acViewnormal means? I forgot to switch back
to
late binding before running my last test.

Now that I am using late binding again it shows a dialog which I would
like
to avoid.

With late binding, I don't think you're going to be able to use the defined
constant acViewNormal. You can either pass its actual value, which is 0, or
just leave it out altogether, as I suggested, because acViewNormal is the
default value for that argument of the OpenReport method.
 
T

TrussworksLeo

Dirk,

Is there a list somewhere that shows the
-- OpenReport method
and the possible argument values?

Thank You, Leo
 
T

TrussworksLeo

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