Solved

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

Posted on 2009-06-30
6
353 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
[X]
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
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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…
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 …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

623 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