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

Posted on 2009-06-30
Medium Priority
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
    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
    End If

'Show Report

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.

Question by:rayluvs
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
  • 5

Author Comment

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.

Accepted Solution

rayluvs earned 0 total points
ID: 24768637

Author Comment

ID: 24768643

How do I go about this? Delete the question? Awarded? What's the next step in a situation like this?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 20

Expert Comment

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


Author Comment

ID: 24794759

Author Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

719 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