Computer Learning Zone CLZ Access Excel Word Windows

All the world is a laboratory to the inquiring mind.

-Martin Fisher
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Working on SQL Part 2    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Working on SQL Part 2
Mubeezi Micah 

15 years ago
Dear Richard,

Below is an example. I have a simple Patient Details table (PtDetailsT, which you often call CustomerT). It has five fields namely PatientID, PtName, Age, Sex and DateRxStarted (read the later as the date when the patient started treatment).
Now, each patient is expected to come back for medical review after one month. So i build a query as follows
SELECT PtDetailsT.PatientID, PtDetailsT.PtName, PtDetailsT.Age, PtDetailsT.Sex, PtDetailsT.DateRxStarted, DateAdd("d",30,[DateRxStarted]) AS FirstReviewDate FROM PtDetailsT;

If i use the above SQL statement to populate my listbox, it is rejected. The VBA editor highlights the "d" in the DateAdd function.

It gets even worse if i add more calculated fields in the query e.g., i may not want FirstReviewDate to fall on a weekend or i may also want to compute by how many days the patient is late for review or which patients will be coming for review soon. See below;
SELECT PtDetailsT.PatientID, PtDetailsT.PtName, PtDetailsT.Age, PtDetailsT.Sex, PtDetailsT.DateRxStarted, DateAdd("d",30,[DateRxStarted]) AS FirstReviewDate, Weekday([FirstReviewDate]) AS DayOfWeek, CDate(nz(IIf([Dayofweek]=7,DateAdd("d",2,[FirstReviewDate]),IIf([Dayofweek]=1,DateAdd("d",1,[FirstReviewDate]),IIf([Dayofweek] Between 2 And 6,DateAdd("d",0,[FirstReviewDate])))))) AS ExactFirstReviewDate, DateDiff("d",[ExactFirstReviewDate],Date()) AS DaysLate FROM PtDetailsT;

So question is, how -without building yet another query- do i use the an SQL statement from a query with calculated fields to populate a listbox or a report?

Best regards,

MICAH


Reply from Richard Rost:

Micah, I don't have that problem. DateAdd should work in your SQL statement. I just tested it with one of my sample databases, and it worked fine. I used this as the SQL rowsource for one of my list boxes:

SELECT ProductID, ProductName, LastUpdated, DateAdd("d",30,[LastUpdated]) AS mDate FROM ProductT;

No problems. It worked the first time. Now, I'm using Access 2010, but I also tested it in Access 2003. No problems with either version. You can use many Access functions in SQL statements like this just fine. I'd need to see your database to tell you what the problem is.

Try creating a blank new table with a couple of simple fields and make a new form with a list box and see if that works. If it works, perhaps it's an issue with your table or existing form.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Working on SQL Part 2.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/16/2026 1:52:40 AM. PLT: 1s