Solved

CreateReportControl Method

Posted on 1998-08-09
2
740 Views
Last Modified: 2013-11-25
I am trying to create an Access Report from VB5.
I have successfully created the report, but I want to Set a Control Object variable, so I can use the controls properties.

I have the following code in a Button_Click event

    Dim appAccess As Access.Application
    Dim rpt As Report
    Dim ctlText As Control
    Dim ctlLabel As Control

    Set appAccess = New Access.Application
    appAccess.OpenCurrentDatabase db.Name
       
    Set rpt = appAccess.CreateReport(CurrentDb.Name)
' This next line produces a run time error #13 - type mismatch
    Set ctlText = rpt.Application.CreateReportControl _
    (rpt.Name, acTextBox, acDetail, "", "PointNumber", , , 1000, 260)
   
    Set ctlLabel = rpt.Application.CreateReportControl _
    (rpt.Name, acLabel, acPageHeader, ctlText.Name, "", , , 1000, 260)

It works fine if I just use,
rpt.Application.CreateReportControl _
    (rpt.Name, acTextBox, acDetail, "", "PointNumber", , , 1000, 260)
But when I try to set it = ctlText, the error #13 results.
From all of the examples I've read, this should work!!
The instance of Access and CreateReport works fine.
Thanks
0
Comment
Question by:electrick
2 Comments
 
LVL 2

Accepted Solution

by:
percosolator earned 150 total points
ID: 1468380
You are more than likely using examples written for Access.  I tried it in VB5, and got the type mismatch that you did.

Once I cut and pasted the code into Access, Voila!  C'est Magnifique!  (it worked)

What you are encountering is that MS-Access uses VBA (Visual Basic for Applications).  VBA and VB are not the same.

A VB text box is a different animal than an Access Report Textbox, hence, your type mismatch.  The "Control" datatype that was dimensioned is a generic VB datatype for VB controls.

Change your DIM statements to this:

    Dim ctlText As Access.TextBox
    Dim ctlLabel As Access.Label

I Did that in VB5 and it seemed to work (though you don't get any context menus).  The text box worked fine, but every time VB hit the "Set ctlLabel =" statement, VB gave me a GPF and Windows shut it down.

It might be my machine, or an inherent bug, I don't know.  If it works for you, let me know.




0
 

Author Comment

by:electrick
ID: 1468381
That did it!, and I got the same GPF you got.  I've narrowed it down to an "Unhandled Exception" in Module OLEAUT32.DLL.
The function is called VariantCopy(). Must be a flaw in the DLL.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now