Solved

DataReport with Record lines and a Total using VB6 and SQL 2000

Posted on 2009-06-30
6
347 Views
Last Modified: 2013-11-26
I have a report (DataReport) that should read all the records of a particular Vendor and then totals the cost.

Here's is the table contens:
VendorID VendorReceiptNo DifPrecio DiscOtrasNegoc
----------- --------------------- ----------- ---------------------
AA01      AA01RCT1205            654.00     0.00
AA01      AA01RCT1255            123.00     100.0000
AA01      AA01RCT1263      10.00        2.5000

I have a form that asks for the Vendor id (Variable is 'VendorId').

On Form Load, I have the connection:
     Set cnn = Nothing
     Set rstRecord = Nothing
     Set cnn = New ADODB.Connection
     Set rstRecord = New ADODB.Recordset
     Dim lCompanyDB, SqlServerName As String
      SqlServerName = "(local)"
      lCompanyDB = "TWO"
      cnn.Open "Provider=SQLOLEDB; " & _
               "Initial Catalog=" & lCompanyDB & "; " & _
               "Data Source=" & SqlServerName & "; " & _
               "integrated security=SSPI; persist security info=True;"

On the "OK" button on the Select Vendor Screen, I have the both query that first reads recordset of all the Vendors records and another that totals (SUM).  At the end I have a SHOW for the DataReport form:

 Set rstRecord = New ADODB.Recordset

'Read all record of the Vendor
 ssql = "select VendorID, VendorReceiptNo, DifPrecio as Cost1,
                    DiscOtrasNegoc as Cost2 from ces00rp01"
 ssql = ssql & " WHERE vendorid='" & VendorID & "'"
 rstRecord.Open ssql, cnn, adOpenKeyset, adLockOptimistic
 If Not rstRecord.EOF Then
    rstRecord.Close
   Else
    rstRecord.Close
    End If
         
'Get totals
 Dim Cost1, Cost2 As Currency
 Cost1 = 0
 Cost2 = 0
 Set rstRecord = New ADODB.Recordset
 ssql = "select sum(DifPrecio) as Cost1, sum(DiscOtrasNegoc) as Cost2 from ces00rp01"
 ssql = ssql & " WHERE vendorid='" & VendorID & "'"
 rstRecord.Open ssql, cnn, adOpenKeyset, adLockOptimistic
 If Not rstRecord.EOF Then
    Cost1 = rstRecord("Cost1").Value
    Cost2 = rstRecord("Cost2").Value
    rstRecord.Close
   Else
    rstRecord.Close
    End If

'Show Report
 DataReport1.Show

When running it I get this error:
"Invalid Data Source"

2 Questions:

1. How can I fix my code for nolt displaying the error?

2. I didn't create a DataEnvironment1 contents since I place all the connections in the Form Load and the command in the Ok button; is this ok?

3. I can't seem to place the fields in the DataReport1 form (that is, place the record contents fields in Detail Section and place the Totals in the Footer Section).

We are kind'a new to VB.

Thanx
0
Comment
Question by:rayluvs
  • 5
6 Comments
 

Author Comment

by:rayluvs
ID: 24750214
We have resolve the "Invalid Data Source" and the "DataReport with Record lines" thru assistance of EE in another question.

We are still working with displaying totals in the report.  How can we place the totals in the report?

We are using:
    ssql = "select sum(DifPrecio) as Cost1, sum(DiscOtrasNegoc) as Cost2 from ces00rp01"
    ssql = ssql & " WHERE vendorid='" & VendorID & "'"
    rstRecord.Open ssql, cnn, adOpenKeyset, adLockOptimistic

Please advice.
0
 

Accepted Solution

by:
rayluvs earned 0 total points
ID: 24768637
0
 

Author Comment

by:rayluvs
ID: 24768643
Hey!

How do I go about this? Delete the question? Awarded? What's the next step in a situation like this?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 20

Expert Comment

by:alainbryden
ID: 24794667
You can close the question and accept your own solution by clicking "Accept As Solution" at the bottom of a comment.

--
Alain
0
 

Author Comment

by:rayluvs
ID: 24794759
Thanx
0
 

Author Comment

by:rayluvs
ID: 24807553
I see this question in my open question.  Is this closed?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now