Solved

Accessing Microsoft Access report database opens twice why?

Posted on 2012-04-13
10
448 Views
Last Modified: 2012-04-18
Good Afternoon,

I have a vb.net application with an access database backend.  Database is old and has been converted up to 2003 I think but it originated from an older version of access than 2003.

I have been given no choice other than to build the front end for the reservations and to use existing reports that sit inside the database.

I have all working BUT when one of the reports is called for preview with the below (using linkbutton inside gridview) the database and report open TWICE.  My questions are does anyone know why?  If so can you tell me what I am doing wrong?  If not is there any other way to do this in vb.net using the existing reports?


Public Sub thesearchresults_RowCommand(ByVal o As Object, ByVal e As GridViewCommandEventArgs) Handles thesearchresults.RowCommand

        If e.CommandName = "view" Then
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)
            Dim row As GridViewRow = thesearchresults.Rows(index)
            Dim getreservation As Integer = row.Cells(1).Text
            'MsgBox(getreservation)
            Try

                Dim oAccess As Microsoft.Office.Interop.Access.Application
             oAccess = CreateObject("Access.Application")

                ' Open the database
             oAccess.OpenCurrentDatabase(dblocation)
             oAccess.DoCmd.OpenReport("Confirmation", 2, WhereCondition:="[Reservation_ReservationNum]=" & getreservation & "")
 
                oAccess.DoCmd.Maximize()
                oAccess.Visible = True
            Catch ex As Exception
                'MsgBox(ex.Message)
                'MsgBox(ex.StackTrace)
                errhandler.WriteError("manage-reservation.aspx and procedure is thesearchresults rowcommand and user is " & Session("theuser"), ex.Message & " " & ex.StackTrace)
                Response.Redirect("CustomError.aspx?thetype=" & ex.Message)
            Finally
                oAccess = Nothing
            End Try
            End If
    End Sub
0
Comment
Question by:thamilto0410
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 58
ID: 37844207
It's just this one report?   The above code looks fine...I don't see any issues.

Jim.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 37844843
JDettman--So far it is just this one report.  I have many others in this access DB I inherited but so far the others I only need to generate a printout which works well ie:open db send to printer close db.  For this report the user needs the ability to preview and when I open for preview the DB opens and displays report twice.
0
 
LVL 5

Expert Comment

by:DoveTails
ID: 37845627
Sounding like the report may be the issue.
Any chance there's something going on with the report itself ?....
such as code for a text box that fits multiple records    ie.   IIf([Field])="1","2"
0
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 1

Author Comment

by:thamilto0410
ID: 37846131
DoveTails:  As I haven't worked with Access or its reports for many years (primarily develop with Oracle) I had not thought of that.  I will tear the report down looking for trouble and let you know.  Thanks.
0
 
LVL 58
ID: 37846268
Yes, I would try and use a copy of Access and see if the report opens normally there.

Jim.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 37857983
JDettman :  The report does open normally in access and there is not anything wrong with the query it does run and populate the report with all fields pulled in the only problem is that in the vb app the db opens twice and the report displays twice.  

Any other suggestions from anyone?
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 37858028
Any chance your code is getting called 2x?  Put a message box up or something when you run through the routine to see if it's getting called twice.

Jim.
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 37858620
JDettman:  You are correct.  I put in the msgbox and it displays twice so the procedure is getting called twice.  I am using a linkbutton and onrowcommand.  so what do I do change to something else?
0
 
LVL 1

Author Closing Comment

by:thamilto0410
ID: 37860280
Thank you JDETTMAN.  I figured it out.  I AM AN IDIOT.  Your last post about the procedure getting called twice helped me to get my head out of the clouds and stop blaming it on the DB and to go over the code again and I KNOW NOT TO call the procedure in the gridview and in the codebehind but I had accidentally done that and then could not see the forest for the trees.  THANKS SO MUCH.
0
 
LVL 58
ID: 37860435
I wouldn't call yourself an idot; stuff like that is easy to do!  Programming is a complicated business and computers never let you forget a mistake<g>.  You should see some of the ones I've pulled over the years...

Glad to hear you've got it figured out.

Jim.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question