?
Solved

CreateReportControl Method

Posted on 1998-08-09
2
Medium Priority
?
785 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
[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
2 Comments
 
LVL 2

Accepted Solution

by:
percosolator earned 450 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

801 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