473,395 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataReport in visual basic 6

1
Hi, i'm trying to make DataReport with VB 6. But got Run-time error '13': Type mismatch. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdGenerateReport_Click()
  2.     Dim conString As String
  3.     conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\" & "Database.mdb;"
  4.  
  5.     Set con = New ADODB.Connection
  6.     con.Open conString
  7.  
  8.     Set rec = New ADODB.Recordset
  9.  
  10.     query = "select name from ms_people"
  11.  
  12.     rec.Open query, con, adOpenStatic, adLockOptimistic
  13.  
  14.     If rec.RecordCount > 0 Then
  15.         Set DataReport1.DataSource = rec
  16.         DataReport1.Sections("Section1").Controls("Text1").DataField = "name"
  17.         DataReport1.Show
  18.     End If
  19.  
  20.     rec.Close
  21. End Sub

The code error at 'Set DataReport1.DataSource = rec'.
DataReport1 is a simple data report (i didn't change the attributes)
Any help would be very grateful >.<. Thanks
Nov 20 '07 #1
1 3182
QVeen72
1,445 Expert 1GB
Hi,

Declare the variables and try this modified code:


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdGenerateReport_Click()
  2.     Dim conString As String
  3.     Dim con
  4.     Dim Rec
  5.     conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\" & "Database.mdb;"    
  6.     Set con = New ADODB.Connection
  7.     con.Open conString
  8.  
  9.     Set rec = New ADODB.Recordset
  10.     rec.CursorLocation = adUseClient
  11.  
  12.     query = "select name from ms_people"            
  13.     rec.Open query, con, adOpenStatic, adLockOptimistic
  14.  
  15.     If rec.RecordCount > 0 Then
  16.         Set DataReport1.DataSource = rec
  17.         DataReport1.Sections("Section1").Controls("Text1").DataField = "name"
  18.         DataReport1.Show
  19.     End If
  20. End Sub


Remove rec.Close, otherwise the report will not show, as the object gets closed..
Check for these:
Database availabe in mentioned path..
Table/Field Names,
and DataReportName and a Text1 Control in Section1


REgards
Veena
Nov 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: berthelot samuel | last post by:
Hi everyone, I am currently trying to write a report based on a View of SQL Server. Basically, I have 3 tables : Hardware, SoftwareInstalled and Software with SoftwareInstalled that keeps track of...
5
by: anoopgopal007 | last post by:
Hi, I am using vb6 and datareport. I am updating the tables whle the program running. But the datareport doesnot show the updated information. Its always shows the previous value. But...
6
by: pramodrepaka | last post by:
hi this is pramod i am facing a small problem Private Sub Command_Click() Dim a As String a = InputBox("enter empno") If rs.State = 1 Then rs.Close rs.Open "select * from microbiology...
0
by: nishjee | last post by:
Hello friends, i need visual basic 6.0 code to export a datareport to html other than the defult option coming with datareport. I need this very urgently because when i am exporting the datareport...
0
by: akintola kolawole | last post by:
How Do I Use Datareport In Visual Basic
1
by: Thinua | last post by:
Hi i'm new to Visual Basic. I have got a copy of vb 6. The problem i have is to get DataReport open a file path with a picture inside it. the file path is stored into a database table field. Can...
1
pentahari
by: pentahari | last post by:
How can i print the selected field and view the print preview with out data report or report viewer using visual basic 6.0.
0
angstangel
by: angstangel | last post by:
hello. :) we have a project in school which requires us to develop a database. I have problems in printing pictures of the whole table. when i print the whole table, only one picture is displayed for...
1
by: MaryKJolly | last post by:
I got this sample project from a website. But there is some syntax error in the statement which contains the CDate function. I can't detect the error? Can enybody help me? SUMMARY This article...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.