Solved

Accessing Microsoft Access report database opens twice why?

Posted on 2012-04-13
10
442 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
  • 5
  • 4
10 Comments
 
LVL 57
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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 57
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 57

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 57
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

685 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