AllExperts > Experts 
Search      

VB Script

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB Script Answers
Question Library

Ask a question about VB Script
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Miguel Zapico
Expertise
I can answer question about how to use scripts to consolidate data, connect different systems and automate tasks. I have no experience on using VBScript on web programming.

Experience
I have been using VBScript and Windows Scripting Host as my swiss tool for the last 6 years.

Organizations
New York PC users group (NYPC)
Independant Computer Consultants Association (ICCA)

Education/Credentials
Microsoft MCSE in Windows NT

 
   

You are here:  Experts > Computing/Technology > Basic > VB Script > DATA GRID

Topic: VB Script



Expert: Miguel Zapico
Date: 6/16/2006
Subject: DATA GRID

Question
Hi,
I was wondering if someone could help me. I am developing a form in vb 6.0
which has a MS Access db running behind it. On the from, I have a
data grid which retrieves the information of customers (name, payment …..)
From that db and outputs it to the screen.
My problem is that I need to create a button on which I click
And should give me the sum of payments (on a label) of all customers and another
button for the sum of payments for each customer (on a label). I am sure that I have to use SQL but how to do it please.
By the way I did the DB Access connection not in code , I did it manually in the properties of the adodc.
Thank you very much.


Answer
I don't have vb installed, so I'll try to answer the best I can.  This is a code that queries a database in vbscript, it may give you some ideas.
Sub AskData()
   Dim strSQL
   set miRec = CreateObject("ADODB.Recordset")
   
   strSQL = "SELECT SUM(Payments) FROM Customers"

   With miRec
  .ActiveConnection = gconIT
      .Open strSQL
  WScript.Echo .Fields(0).Value
   End With

   miRec.Close
End Sub

The idea is, create a connection object (that is the gconIT, you may need to know how your connection is called), create a ADODB.Recordset, that will use that connection, and with the method Open of the recordset you can craft a SQL expression.
If you have doubts about the SQL expression, do it in Access with the wizard, and then see the code on the SQL view.
In order to put on a label, change the Wscript.Echo order to the appropiate label changing code.

Hope this helps,
Miguel.


Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.