?
Solved

VB6 Datagrid with ADO - Select Sum question

Posted on 2002-03-04
4
Medium Priority
?
1,481 Views
Last Modified: 2012-06-21
Hi there,

I'm fairly new to VB and having problems using a SQL statement with VB6.  In my application I have two tables called Job and Labour.  A job can have many 'labours' (for example an employee does work, I've made that a 'labour' for a particular job number).  So in the Job table there is a field called Job Number.  In the Labour table there is a Total Time field.  

In my VB application I have two forms, a Job form and a Labour form.  The Job form launches first and is simple with a datagrid, an ADO control, and a bunch of text fields and combo boxes.  The Labour form is spawned from the Job form by double clicking a record in the datagrid and then I just use a SQL statement to select all 'labours' where they equal the job number in the job table.

Anyways, that all works fine.  My problem is that I want to display a text field on the Job form that adds up all of the Labours TotalTime field.  So basically if a Job has three Labours, or stuff done on it, then I want to add those three fields together and display one total on the Job form.  I realize that is what the Sum part of the SQL statement is for, and I can easily get the textfield to display the total time on the Job form, grabbing and summing the records from Labour where they have the same Job number.  I should mention I do this in the Form_Load procedure.  

So that works.  What doesn't work is that if I change rows (I've got a toolbar up top) then it keeps reading the same value...of the first Job number.  So I tried combating that by finding the datagrid property which will tell me that the row has changed.  I've tried all of them listed pretty much that pertain to setting the focus of the row.  None of them seem to work.

To summate:  How do I display a textfield total value and update that value as I change rows, either by using my toolbar to MoveNext or by just clicking the datagrid.  (it is enabled, but doesn't allow updates).  Basically I want to query the database each time a new row has gotten the focus and sum all values in a column where their job number is the job number of the row selected.

If anyone needs more info feel free to ask, I'd love to solve this annoying obstacle.  Thanks a lot!  
0
Comment
Question by:bigfish777
[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
4 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 800 total points
ID: 6838785
Use the RowColChange event.

Also, give a try to the Data Form Wizard to generate a Master/Detail (Labour/Job) in your case.
0
 
LVL 1

Expert Comment

by:S2
ID: 6838960
Don't use the datagrid use the MSHflexgrid it's simple to use and it's much more powerfull.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6838983
You could also use the MoveComplete event of the ADO Datacontrol to achieve this.
0
 

Author Comment

by:bigfish777
ID: 6839731
Thanks a bunch.  I totally missed RowColChange for some reason...it does exactly what I want.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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, 3 hours left to enroll

764 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