Solved

CreateReportControl Method

Posted on 1998-08-09
2
749 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

770 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