Solved

CreateReportControl Method

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 69
VBA open file from excel cell 4 44
How to set the sa password in a vb6 code for sql connection 9 60
Hide vba in gp 7 106
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 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