Using DataReports without DataEnvironment 
Author Message
 Using DataReports without DataEnvironment

I am trying to build a DataReport without using a DataEnvironment or
Connection.  I am using an Access Database.

Can anyone please give me some sample code to populate the fields in a
report using code.  I have the following code, and the only error
message I get is "Report sections do not match datasource".
I have tried using a Datashape to connect, however, I do not
comprehend how to do many table joins using SHAPE command.

I would really appreciate any help on the whole reports issue.
Also, I have actually managed to build the report in MS Access using 2
queries, so if anyone can tell me how to run a MS Access report from
Visual Basic, that would also help.

Julie (sick to death of fighting VB)

    cn.CursorLocation = adUseClient
    cn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security
Info=False;Data Source=" & App.Path & "\storage.mdb"

   SQL = "SELECT ContactID, CompanyName, Fullname, Address1, " & _
    "Address2, CityTown, State, Postcode, Country, BalBrOpen " & _
   "FROM Contact"

    rs1.Open SQL, cn, adOpenStatic, adLockReadOnly

Set DataReport1.DataSource = rs1

If rs1.RecordCount > 0 Then
   With DataReport1
        With .Sections("contact")
            .Controls("txtContactID").DataField = "ContactID"
            .Controls("txtCompanyName").DataField = "CompanyName"
            .Controls("txtName").DataField = "FullName"
            .Controls("txtAddress1").DataField = "Address1"
            .Controls("txtAddress2").DataField = "Address2"
            .Controls("txtCity").DataField = "CityTown"
            .Controls("txtstate").DataField = "state"
            .Controls("txtpostcode").DataField = "postcode"
            .Controls("txtcountry").DataField = "country"
            .Controls("txtBalBrOpen").DataField = "BalBrOpen"

        End With
    End With
End If



Mon, 17 Dec 2001 03:00:00 GMT
 Using DataReports without DataEnvironment

Quote:

> I am trying to build a DataReport without using a DataEnvironment or
> Connection.  I am using an Access Database.

...and the reason for not using DataEnvironment/Connection/Command is?
  I took a deep breath and learned the basics of using the
DE/Conn/Command approach, and it's not THAT bad (I mean, if I can learn
it....).  I'd be glad to try to answer basic questions on using it for
your report.
  All the MS documentation seems to show DE as the DataSource for
DataReports, even though they use the phrase "a DataSource such as a
DataEnvironment" - they never illustrate how to use anything else.  Mr
Gates wants us all to stop griping and just use the DE!
  Seriously, some time browsing the Knowledge Base would probably be the
best way to see if they've posted examples of using other DataSources
for DataReport.
  Good luck ...and if you find such documentation, please post it here -
you will be our new consultant on non-DE DataSources!
--
Jim in Cleveland
If you're writing to me, in my address
change "REAL_Address.see.below" to "worldnet.att.net"

"What's so funny 'bout peace, love & understanding?"
     - Nick Lowe



Mon, 17 Dec 2001 03:00:00 GMT
 Using DataReports without DataEnvironment
Julie,
Here's one way to do it. I think that if you have a database you can
connect to the easiest way by far is to use the DE. But here goes
anyhow:

use this code to create a connection to the Database:

   Dim primaryRS As Recordset
   Dim db As Connection

   Set db = New Connection
   db.CursorLocation = adUseClient
   db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" & App.Path
& "\TrpSheet.Mdb;"

   Set primaryRS = New Recordset
   primaryRS.Open "SELECT ContactID, CompanyName, Fullname, _
Address1,  Address2, CityTown, State, Postcode, Country, _
 BalBrOpen FROM Contact", db, adOpenStatic, adLockReadOnly

   Set DataReport1.DataSource = primaryRS

Don't try to force the values into the report textboxes. For each text
box put the datafield in the properties window at runtime.
Example for the txtContactID textbox:

DataField     ContactID

It should work if you haven't already finished the DE

Good luck
Jeff



Quote:
>I am trying to build a DataReport without using a DataEnvironment or
>Connection.  I am using an Access Database.

>Can anyone please give me some sample code to populate the fields in a
>report using code.  I have the following code, and the only error
>message I get is "Report sections do not match datasource".
>I have tried using a Datashape to connect, however, I do not
>comprehend how to do many table joins using SHAPE command.

>I would really appreciate any help on the whole reports issue.
>Also, I have actually managed to build the report in MS Access using 2
>queries, so if anyone can tell me how to run a MS Access report from
>Visual Basic, that would also help.

>Julie (sick to death of fighting VB)

>    cn.CursorLocation = adUseClient
>    cn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security
>Info=False;Data Source=" & App.Path & "\storage.mdb"

>   SQL = "SELECT ContactID, CompanyName, Fullname, Address1, " & _
>    "Address2, CityTown, State, Postcode, Country, BalBrOpen " & _
>   "FROM Contact"

>    rs1.Open SQL, cn, adOpenStatic, adLockReadOnly

>Set DataReport1.DataSource = rs1

>If rs1.RecordCount > 0 Then
>   With DataReport1
>        With .Sections("contact")
>            .Controls("txtContactID").DataField = "ContactID"
>            .Controls("txtCompanyName").DataField = "CompanyName"
>            .Controls("txtName").DataField = "FullName"
>            .Controls("txtAddress1").DataField = "Address1"
>            .Controls("txtAddress2").DataField = "Address2"
>            .Controls("txtCity").DataField = "CityTown"
>            .Controls("txtstate").DataField = "state"
>            .Controls("txtpostcode").DataField = "postcode"
>            .Controls("txtcountry").DataField = "country"
>            .Controls("txtBalBrOpen").DataField = "BalBrOpen"

>        End With
>    End With
>End If



Sun, 23 Dec 2001 03:00:00 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Using DataReports without DataEnvironment

2. Grouping in DataReport without DataEnvironment

3. Datareport without Dataenvironment designer ?

4. Grouping in DataReport without DataEnvironment

5. DataReport without DataEnvironment

6. Using the VB6 DataEnvironment and DataReport designers

7. datareport using dataenvironment

8. DATAENVIRONMENT, DATAREPORTS

9. VB6 Dataenvironment & Datareport

10. MS-SQL - VB 6/DataEnvironment/DataReport


 
Powered by phpBB® Forum Software