473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Failure of OpenDatabase Method

Hi,

My computer just hiccuped, so if this went through already, my
apologies.

I am attempting to have a User access a report in a separate
application based on the value from a combo box, but it fails. Any
help you can lend would be appreciated.

Here is the code...

==========

Private Sub cmdPreviewReport_Click()

Dim rptTitle As String
Dim wsp As Workspace
Dim dbs As Database
Dim dbsAnother As Database

' Return reference to current database.
Set dbs = CurrentDb

' Return reference to default workspace.
Set wsp = DBEngine.Workspaces(0)

' Return reference to the Reports database
Set dbsAnother = wsp.OpenDatabase("\\NETWORKLOCATION\Reports.mdb")

rptTitle = Me.cboReports.Column(0)

DoCmd.OpenReport Me.cboReports, acViewPreview

Set dbs = Nothing
Set dbsAnother = Nothing

End Sub

==========

Henry

Feb 10 '06 #1
1 6952
"Henry Stockbridge" <hs***********@hotmail.com> wrote in message
news:11********************@z14g2000cwz.googlegrou ps.com...
Hi,

My computer just hiccuped, so if this went through already, my
apologies.

I am attempting to have a User access a report in a separate
application based on the value from a combo box, but it fails. Any
help you can lend would be appreciated.

Here is the code...

==========

Private Sub cmdPreviewReport_Click()

Dim rptTitle As String
Dim wsp As Workspace
Dim dbs As Database
Dim dbsAnother As Database

' Return reference to current database.
Set dbs = CurrentDb

' Return reference to default workspace.
Set wsp = DBEngine.Workspaces(0)

' Return reference to the Reports database
Set dbsAnother = wsp.OpenDatabase("\\NETWORKLOCATION\Reports.mdb")

rptTitle = Me.cboReports.Column(0)

DoCmd.OpenReport Me.cboReports, acViewPreview

Set dbs = Nothing
Set dbsAnother = Nothing

End Sub

==========

Henry


The OpenCurrentDatabase method is required to open a report in a separate
application.

Paste the following code into a new Module and save it as
"modOLEOpenReport". Then modify your code thus:

Private Sub cmdPreviewReport_Click()

Dim rptTitle As String

rptTitle = Me.cboReports.Column(0)
OLEOpenReport "\\NETWORKLOCATION\Reports.mdb", rptTitle, ,
acViewPreview

End Sub

See if this works for you.
Microsoft References:
Article 145707: ACC: How to Use Automation to Print Microsoft Access Reports
Article 317113: How To Automate Microsoft Access From Visual Basic .NET

'--------------------<<< Begin Code >>>--------------------
' This function was originally posted under Microsoft Article
' 145707, and has been modified to incorporate the
' method to connect to an external, password-protected
' database as described in Microsoft Article 317113.

Function OLEOpenReport(strDBName As String, _
strRptName As String, _
Optional sDBPassword As Variant, _
Optional ByVal intDisplay As Variant, _
Optional ByVal strFilter As Variant, _
Optional ByVal strWhere As Variant) As Boolean

On Error GoTo OLEOpenReport_Err

Dim objAccess As Object
Dim objDBEngine As DAO.DBEngine
Dim objDB As DAO.Database

' Create new instance of Microsoft Access
Set objAccess = CreateObject("Access.Application")

If Not IsMissing(sDBPassword) Then
' Establish a DAO connection to an external
' database under password protection
Set objDBEngine = objAccess.DBEngine
Set objDB = objDBEngine.OpenDatabase(strDBName, _
False, False, ";PWD=" & sDBPassword)
End If
' Open the external database in the new Access instance
objAccess.OpenCurrentDatabase strDBName, False
If Not IsMissing(sDBPassword) Then
objDB.Close
Set objDB = Nothing
Set objDBEngine = Nothing
End If

If IsMissing(intDisplay) Then intDisplay = acNormal
If IsMissing(strFilter) Then strFilter = ""
If IsMissing(strWhere) Then strWhere = ""
' If view is acViewDesign or acViewPreview then
' maximize the new Access session instance
If intDisplay > 0 Then
objAccess.DoCmd.RunCommand acCmdAppRestore
objAccess.DoCmd.RunCommand acCmdAppMaximize
End If
' Open the report with the specified parameters
objAccess.DoCmd.OpenReport strRptName, _
intDisplay, strFilter, strWhere

' If view is acViewDesign or acViewPreview then
' maximize the report display
If intDisplay > 0 Then objAccess.DoCmd.Maximize

' If view is acViewDesign or acViewPreview then
' wait for the user to close the report
Do While intDisplay > 0 And objAccess.SysCmd( _
acSysCmdGetObjectState, acReport, strRptName) > 0
DoEvents
Loop

' Close new Access session instance
objAccess.Quit acExit

Set objAccess = Nothing
OLEOpenReport = True
OLEOpenReport_End:
Exit Function

OLEOpenReport_Err:
MsgBox error$(), vbInformation, "Automation"
Resume OLEOpenReport_End
End Function
'---------------------<<< End Code >>>---------------------
Feb 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: redcard | last post by:
Hi, I'm opening a database using the following code: Set m_dbDatabase = OpenDatabase("", False, False, strOdbc) Works OK and connects to the database with no problem. If however while I'm...
5
by: Mark | last post by:
Hi, I can't seem to find any documentation as to how STL indicates method failure, whether by return code or exception. e.g how would I test for out of memory case when inserting into a...
5
by: Les Desser | last post by:
Spent hours till I pinned down that on an XP machine the OpenDatabase method causes MDE creation to fail while a compile produces no error. A reference in a Google reference pointed me to...
2
by: Jozef | last post by:
Hello, I have a database that I have passworded. When I try to use OpenDatabase with the Connect parameter filled in, I keep getting "Not a valid password", even if I use the actual connect...
4
by: kids_pro | last post by:
Hi there, I am using DAO to read data from MDB file I try the following command to open database. DBEngine dbEng = new DBEngineClass(); Workspace ws = dbEng.Workspaces; db =...
0
by: mo. | last post by:
I need some help in accessing Jet database using DAO. I have just started to learn c# and am trying to rewrite a program I have in vb.net to c#. In VB.Net I can do this: Dim ws As...
5
by: Ron Louzon | last post by:
I have some C++ code that uses the CSingleLock( CCriticalSection *) constructor. In visual C++ 6.0, this code compiles and runs fine in both Debug and release modes. However, in Visual Studio...
2
by: Andy | last post by:
I am new to .NET so not sure if this is the right process... Any help will be greatly appreciated. I am trying to eliminate the grey login box that pops up when Windows Authentication is used by...
0
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.