473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Summing data using SQL expressions in Visual Basic...

patjones
931 Expert 512MB
Hi:

I have two date fields, fldDateOfNoPayBegin and fldDateReturned in a table in my database. My goal is simple: I want to take the difference between the two for each record, and then sum that over all records. The result goes into a text box txtLostDaysNoPay on a form.

I've had success by setting the Control Source property for txtLostDaysNoPay (via the Properties box in Access) equal to

Expand|Select|Wrap|Line Numbers
  1. =Sum(DateDiff("d",[tblWC]![fldDateOfNoPayBegin],[tblWC]![fldDateReturned]))
My issue is that I want to be able to do this strictly in the VB module for the form. I've tried writing a few SELECT statements in VB to accomplish it, but then I can't run those statements because the DoCmd.RunSQL method will only run action queries.

Just want to keep everything in the VB module as much as possible. Thanks!

Pat
Sep 18 '07 #1
2 1496
MMcCarthy
14,534 Expert Mod 8TB
Hi Pat

Something like this should work.

Me!txtLostDaysNoPay = DSum(DateDiff("d", [fldDateOfNoPayBegin], [fldDateReturned]), "tblWC")
Sep 19 '07 #2
patjones
931 Expert 512MB
That works like a charm, and has clearly saved me a couple of hours of confusion at work today. Thanks so much!

I just have to note that the first argument in the DSum function is a string, so the DateDiff function needs to be enclosed in quotes like so:

Expand|Select|Wrap|Line Numbers
  1. Me!txtLostDaysNoPay = DSum("DateDiff('d', [fldDateOfNoPayBegin], [fldDateReturned])", "tblWC")
Hi Pat

Something like this should work.

Me!txtLostDaysNoPay = DSum(DateDiff("d", [fldDateOfNoPayBegin], [fldDateReturned]), "tblWC")
Sep 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Yaroslav Bulatov | last post by:
I made an array of 10 million floats timed how long it takes to sum the elements, here's what I got (millis): gcc -O2: 21 Python with numarray: 104 Python with Numeric: 302...
0
by: me | last post by:
I've posted this in the microsoft news group but just noticed the comp newsgroups. What's the difference anyways? This one is a tricky one so I'm interested in seeing what all you gurus have to...
0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
0
by: Stylus Studio | last post by:
Stylus Studio 6 XML Enterprise Edition Now Integrates with TigerLogic XDMS XQuery and Native XML Database Bedford, MA, -- Stylus Studio ( http://www.stylusstudio.com ), the industry-leading...
3
by: Sathyaish | last post by:
I wanted to practice some Linked List stuff, so I set out to create a linked list. The plan was to create the following: (1) A linked list class in Visual Basic (2) A non-class based linked list...
0
by: Susan | last post by:
We purchased Visual Basic .NET version 2003 Standard I am trying to connect to an Informix database using ODBC with Visual Basic ..NET. I created the ODBC connection, and it tests OK. When I go...
5
by: rogsonl | last post by:
My computer was moved last week, and the company changed the network groups we work on. As a result, one of the main benefits from Whidbey (database connectivity) no longer works. Situation: 1....
0
by: ME | last post by:
I can't seem to delete records using an objectdatasource. The object is a Typed Collection built by Visual Studio that access a SQL Database. When I try to delete using the ObjectDataSource it...
7
by: vbnetdev | last post by:
My boss wants this done in a day. I would be happy with a week! Anyway, I have a dataset filled with data and need to populate an MS word chart with it when writing a report. Any tutorials or...
9
by: a | last post by:
Dear friends I want import data from CSV file to mdb file How can I do that in vb.net?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.