-
WSDrew
AskWoody LoungerHere’s the SQL for a single query solution:
SELECT ProdID, yearno, weekno, T1.sold, (SELECT TOP 1 itemsperbox FROM itemsize WHERE (itemsize.yearno=T1.yearno AND itemsize.weekno<=T1.weekno) OR itemsize.yearno<T1.yearno ORDER BY yearno DESC, weekno DESC) AS ItemsPerBox, (SELECT TOP 1 itemsperbox*T1.sold AS total FROM itemsize WHERE (itemsize.yearno=T1.yearno AND itemsize.weekno<=T1.weekno) OR itemsize.yearno<T1.yearno ORDER BY yearno DESC, weekno DESC) AS total
FROM sold AS T1
ORDER BY ProdID, yearno, weekno;I used itemsize and sold as the table names, per your post, but I would recommend changing them to tblItemSize and tblSold. (the sold table has a sold field…which can lead to some confusion.
Note, the query results will have 'nulls' instead of zeros, if there is no itemsperbox value 'yet'. If you must have zeros, then use this (it will just take longer…)
SELECT ProdID, yearno, weekno, T1.sold, IIF(IsNull((SELECT TOP 1 itemsperbox FROM itemsize WHERE (itemsize.yearno=T1.yearno AND itemsize.weekno<=T1.weekno) OR itemsize.yearno<T1.yearno ORDER BY yearno DESC, weekno DESC)),0,(SELECT TOP 1 itemsperbox FROM itemsize WHERE (itemsize.yearno=T1.yearno AND itemsize.weekno<=T1.weekno) OR itemsize.yearno<T1.yearno ORDER BY yearno DESC, weekno DESC)) AS ItemsPerBox, IIF(IsNull((SELECT TOP 1 itemsperbox*T1.sold AS total FROM itemsize WHERE (itemsize.yearno=T1.yearno AND itemsize.weekno<=T1.weekno) OR itemsize.yearno<T1.yearno ORDER BY yearno DESC, weekno DESC)),0,(SELECT TOP 1 itemsperbox*T1.sold AS total FROM itemsize WHERE (itemsize.yearno=T1.yearno AND itemsize.weekno<=T1.weekno) OR itemsize.yearno<T1.yearno ORDER BY yearno DESC, weekno DESC)) AS total
FROM sold AS T1
ORDER BY ProdID, yearno, weekno;You can get zero's with the first query (which would be faster, by putting records in the itemsize table like a,1,1,0, but that may disrupt other systems in your database)
Have fun….
-
WSDrew
AskWoody LoungerJust out of curiousity, does it make a difference if you drop the adCmdTable at the end?
-
WSDrew
AskWoody LoungerJust out of curiousity, does it make a difference if you drop the adCmdTable at the end?
-
WSDrew
AskWoody LoungerCould you post the SQL that the combobox is using?
Also, do you know how many records should be displayed, ie, should it always return 750 records, or is it a bit more flexible then that?
-
WSDrew
AskWoody LoungerCould you post the SQL that the combobox is using?
Also, do you know how many records should be displayed, ie, should it always return 750 records, or is it a bit more flexible then that?
-
WSDrew
AskWoody LoungerNo problem. I think the underscore is used instead of the question mark too. Quite frankly, they would make life a lot easier if they put a note about ADO wild cards in the MSDN under the definitions of ADO’s .EOF and .BOF properties. Because every time a developer who is used to * in Access, goes to ADO and uses * in his SQL, he’s going to get EOF and BOF, not realizing it’s the * acting as a true Asterick.
I was snagged several times by this, because it happened months apart, and I completely forgot to use the percent symbol!
More then likely I’ll snag myself again a few months from now.
Glad to help out….
-
WSDrew
AskWoody LoungerNo problem. I think the underscore is used instead of the question mark too. Quite frankly, they would make life a lot easier if they put a note about ADO wild cards in the MSDN under the definitions of ADO’s .EOF and .BOF properties. Because every time a developer who is used to * in Access, goes to ADO and uses * in his SQL, he’s going to get EOF and BOF, not realizing it’s the * acting as a true Asterick.
I was snagged several times by this, because it happened months apart, and I completely forgot to use the percent symbol!
More then likely I’ll snag myself again a few months from now.
Glad to help out….
-
WSDrew
AskWoody LoungerChange the combobox’s Style to 2 – Dropdown List.
-
WSDrew
AskWoody LoungerChange the combobox’s Style to 2 – Dropdown List.
-
WSDrew
AskWoody LoungerYou could always just use the API method:
Private Declare Function WNetGetConnection Lib “mpr.dll” Alias “WNetGetConnectionA” (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
Function GetUNCPath(strDrivePath As String) As String
Dim strTemp As String
Dim dwReturn As Long
strTemp = Space(255)
dwReturn = WNetGetConnection(strDrivePath, strTemp, 255)
If dwReturn = 0 Then
strTemp = Trim(strTemp)
GetUNCPath = Left(strTemp, Len(strTemp) – 1)
Else
GetUNCPath = “Error”
End If
End FunctionSo on my machine, GetUNCPath(“T:”) returns NasData which is the share path of our T: drive. I have it just returning ‘Error’ if something is wrong, but there is a bunch of specifics you can get from the error message, like ‘network is not present’, etc.
Hope this helps….
-
WSDrew
AskWoody LoungerYou could always just use the API method:
Private Declare Function WNetGetConnection Lib “mpr.dll” Alias “WNetGetConnectionA” (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
Function GetUNCPath(strDrivePath As String) As String
Dim strTemp As String
Dim dwReturn As Long
strTemp = Space(255)
dwReturn = WNetGetConnection(strDrivePath, strTemp, 255)
If dwReturn = 0 Then
strTemp = Trim(strTemp)
GetUNCPath = Left(strTemp, Len(strTemp) – 1)
Else
GetUNCPath = “Error”
End If
End FunctionSo on my machine, GetUNCPath(“T:”) returns NasData which is the share path of our T: drive. I have it just returning ‘Error’ if something is wrong, but there is a bunch of specifics you can get from the error message, like ‘network is not present’, etc.
Hope this helps….
-
WSDrew
AskWoody LoungerInvest in Restorer 2000 Pro. http://www.bitmart.net/r2k.shtml%5B/url%5D Bought it a few years ago, best $30 I ever spent. Bought a personal copy for myself, when I had gone to ‘clean up’ a users machine at work, and completely lost a 6 gig partition full of his actual data files (not OS or program installs, actual data files, like .pst’s, word docs, excel files, etc.). The partition just literally disappeared. (Had reinstalled the OS, and wiped out the first partition, thinking nothing of the fact that the first partition keeps a ‘reference’ to other partitions on a dynamic disk….whooops). So booted to a clean OS, and had NO DATA! Yikes. Spent several hours trying to manually ‘spoof’ the system into seeing the drive, nothing worked. Did a little net research, and found Restorer 2000 Pro (has a demo version for free). Downloaded it, it found the missing partition and all of the data. Bought it, recovered the SIX GIGS of lost data….and was able to go to bed that night….
.
Since then, I have used Restorer 2000 Pro several times. The only time it wasn’t able to help me, is when I lost a 2 segments of a three drive RAID. I had 2 of the 3 segments ‘untouched’, but the OS only saw 1 segment. Restorer ‘sees’ NTFS files whether they’ve been deleted, and it ignores partitions, but RAID’s don’t put data directly on the drive, it puts partial data amongst all the drives. Had to find another utility to recover from that (which was about $50, along with $500 in ‘tech support’, to get the right configuration).
Good luck!
-
WSDrew
AskWoody LoungerInvest in Restorer 2000 Pro. http://www.bitmart.net/r2k.shtml%5B/url%5D Bought it a few years ago, best $30 I ever spent. Bought a personal copy for myself, when I had gone to ‘clean up’ a users machine at work, and completely lost a 6 gig partition full of his actual data files (not OS or program installs, actual data files, like .pst’s, word docs, excel files, etc.). The partition just literally disappeared. (Had reinstalled the OS, and wiped out the first partition, thinking nothing of the fact that the first partition keeps a ‘reference’ to other partitions on a dynamic disk….whooops). So booted to a clean OS, and had NO DATA! Yikes. Spent several hours trying to manually ‘spoof’ the system into seeing the drive, nothing worked. Did a little net research, and found Restorer 2000 Pro (has a demo version for free). Downloaded it, it found the missing partition and all of the data. Bought it, recovered the SIX GIGS of lost data….and was able to go to bed that night….
.
Since then, I have used Restorer 2000 Pro several times. The only time it wasn’t able to help me, is when I lost a 2 segments of a three drive RAID. I had 2 of the 3 segments ‘untouched’, but the OS only saw 1 segment. Restorer ‘sees’ NTFS files whether they’ve been deleted, and it ignores partitions, but RAID’s don’t put data directly on the drive, it puts partial data amongst all the drives. Had to find another utility to recover from that (which was about $50, along with $500 in ‘tech support’, to get the right configuration).
Good luck!
-
WSDrew
AskWoody LoungerJust an added comment about Mark’s default value suggestion. One handy, yet sometimes overlooked, advantage of setting a default value, instead of setting the actual value, is that a default value will display to the user, BUT WILL NOT enter data in the table, until other fields are used. As an example, if Joe User opens your form, enters one record, then moves to a new record, if Joe decides he doesn’t want to enter that record, he’ll just close the form. If you have used code to set the value (not default value) of the field, then you either end up with a partially empty record, with just the ‘automated’ fields filled in, OR if you have data validation in place/required fields, Joe User will get prompts when trying to close the form, because a record was created, but not completed.
On the other hand, if you have your code set the default value, and Joe User closes your form after going to a new record, no ‘partially empty’ records are created, nor does Joe User get any data validation prompts.
I post this once in a while, when I see this type of topic arise, because I’ve been the Joe User too many times, who was plagued with message boxes when I just wanted to close a form!
-
WSDrew
AskWoody LoungerJust an added comment about Mark’s default value suggestion. One handy, yet sometimes overlooked, advantage of setting a default value, instead of setting the actual value, is that a default value will display to the user, BUT WILL NOT enter data in the table, until other fields are used. As an example, if Joe User opens your form, enters one record, then moves to a new record, if Joe decides he doesn’t want to enter that record, he’ll just close the form. If you have used code to set the value (not default value) of the field, then you either end up with a partially empty record, with just the ‘automated’ fields filled in, OR if you have data validation in place/required fields, Joe User will get prompts when trying to close the form, because a record was created, but not completed.
On the other hand, if you have your code set the default value, and Joe User closes your form after going to a new record, no ‘partially empty’ records are created, nor does Joe User get any data validation prompts.
I post this once in a while, when I see this type of topic arise, because I’ve been the Joe User too many times, who was plagued with message boxes when I just wanted to close a form!
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
W11 24H2 – Susan Bradley
by
G Pickerell
1 hour, 35 minutes ago -
7 tips to get the most out of Windows 11
by
Alex5723
3 hours, 43 minutes ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
13 minutes ago -
I installed Windows 11 24H2
by
Will Fastie
1 hour, 47 minutes ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
7 hours, 34 minutes ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
21 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
7 hours, 46 minutes ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
9 hours, 8 minutes ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
20 hours, 27 minutes ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
1 day ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
1 day, 9 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
11 hours, 39 minutes ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
17 hours, 47 minutes ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
1 day, 4 hours ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
2 days, 20 hours ago -
50 years and counting
by
Susan Bradley
10 hours, 46 minutes ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
2 days, 2 hours ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
3 days, 7 hours ago -
Edge : Deprecating window.external.getHostEnvironmentValue()
by
Alex5723
3 days, 7 hours ago -
Rethinking Extension Data Consent: Clarity, Consistency, and Control
by
Alex5723
3 days, 7 hours ago -
OneNote and MS Word 365
by
CWBillow
3 days, 9 hours ago -
Ultimate Mac Buyers Guide 2025: Which Mac is Right For You?
by
Alex5723
3 days, 9 hours ago -
Intel Unison support ends on Windows 11 in June
by
Alex5723
3 days, 9 hours ago -
April 2025 — still issues with AMD + 24H2
by
Kevin Jones
1 day ago -
Windows 11 Insider Preview build 26200.5518 released to DEV
by
joep517
3 days, 21 hours ago -
Windows 11 Insider Preview build 26120.3671 (24H2) released to BETA
by
joep517
3 days, 21 hours ago -
Forcing(or trying to) save Local Documents to OneDrive
by
PateWilliam
4 days, 6 hours ago -
Hotpatch for Windows client now available (Enterprise)
by
Alex5723
3 days, 18 hours ago -
MS-DEFCON 2: Seven months and counting
by
Susan Bradley
2 days, 19 hours ago -
My 3 monitors go black & then the Taskbar is moved to center monitor
by
saturn2233
4 days, 15 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.