-
WSCecilia
AskWoody LoungerSure wish I could. It’s Friday and a beautiful day outside.
-
WSCecilia
AskWoody LoungerHi–
Thanks for the try, but it’s not what I’m after. I have a table that shows who did what on what day. From there, I have a query that shows employees that worked on a weekend or holiday and the hours they reported working.
So my query ends up with
Emp1 Sunday
Emp1 Saturday
Emp2 Sunday
Emp3 Holiday
Emp3 SundayI want to return that there are three individuals reporting that they worked on a weekend or holiday. This is a bit closer to the real life query, so maybe it clarifies what I’m trying to do.
I _could_ get my result by making a group by query for EmployeeID, then counting the number of rows in the query. But I don’t want to use two queries because I’m programmatically changing everything step by step (I know I could change the querydefs, but I don’t want to do that either).
So what I want is the Access97 equivalent of Count(Distinct EmployeeID), which so far has not worked for me, despite the fact that it shows up on page 140 of the Access Developer’s Handbook, and I haven’t been able to find proof that it doesn’t work or a workaround for the issue.
If anyone has any other ideas….
-
WSCecilia
AskWoody LoungerHi Gary….
The table (actually, it’s a query of a larger table) contains a list of employees with the days of the week (in reality, it just picks up employees that worked on a Sat, Sun, or a holiday) and the hours they worked that day. I need to count how many people worked on those days. The trouble is that there is a potential that someone could work Saturday and Sunday and a holiday, so their name shows up three times in the query. When you do a count, it picks up the number of records, not the number of unique individuals.
-
WSCecilia
AskWoody LoungerAlmost. I’m looking for
Count(Distinct EmpNumber)
Which would return 2 as the result. But it doesn’t seem to work in Access 97, so I’m looking for an alternative and/or confirmation that it just doesn’t work.
If you do Count(EmpNumber), the answer is 4 since there are four records. I know you can do the above with two queries (first is a group by, then a count), but I’m trying to do it with just one query.
-
WSCecilia
AskWoody LoungerSure, I do this all the time. You’ll want to look up something the Print # statement (in Access help):
Open strFileName For Output As hFile
Print #hFile, strHeader
Print #hFile, strTitle
Print #hFile, strTOC
Print #hFile, strText
Print #hFile, strFooter
Close #hFileThere’s also the TransferText methods.
Good luck!
Cecilia
-
WSCecilia
AskWoody LoungerHi Hans!
Thank you so much for sharing this! It is incredibly more elegant than the original example (all those on formats and such–uggggh!).
Beautiful!
Cecilia
-
WSCecilia
AskWoody LoungerHmmm. Wisdom=none. Humor, well, if sarcasm counts, I’ve got tons
You can actually put the function directly in the criteria of the query. Instead of just hte In string, make sure it includes the in and paren, then you can call the function directly from the design grid, ie. SelectedItems(Forms!myForm.listbox1)
To build a report, you can even use the results of the in string in the where….Something like
DoCmd.OpenReport “myreport”,,,,,(I don’t know how many commas) “Criteria in (” & SelectedItems(me.listbox1) & “)”
Or again, from the OnOpen of the report….
Me.recordsource=”Select field from table where criteria in (” & SelectedItems(me.listbox1) & “)”Hope this makes sense….
-
WSCecilia
AskWoody LoungerThis is the part where my brain cells stop working, because I’m a visual type person….
Are you trying to populate a listbox? Can you run through the steps that you want the user to make?
For instance, if I want to populate a listbox after the user selects something in a combo, I would (probably) use the afterupdate event of the combo to set the recordsource of the listbox and refresh the form/listbox. The function returns the IN part, so you’d have to modify it to have a whole select statement that would fit into the recordsource. (ie. listbox2.recordsource=”Select stuff where criteria in (” & SelectedItems(me.listbox1) & “)”
Although now I’m getting confused as to why we’re bouncing from control to control….wouldn’t that make your users a bit crazy?
Maybe someone else can jump in here?
-
WSCecilia
AskWoody LoungerThis looks cool! I’m going to play with it, but I think between your example and the reference above, I’ve got it!
Thanks!
Cecilia
-
WSCecilia
AskWoody LoungerHi!
The issue with the sheet tab is this: My report contains five rows at the top that have a top header, and the first two columns on the left are the left hand header. Then I have about 30 columns going across the page.
When I print the sheet, I want each sheet to have the top header and the left header. But since the top header only occurs above the first few columns, it doesn’t repeat itself across the pages.
Thanks for the reference, part of the struggle here is that I’m not even sure what I should be looking for!
Cecilia
-
WSCecilia
AskWoody LoungerHi Charlotte–
I think I was going overboard with helping out the users. The problem is that some of us map our drives to different letters because we move around between regions and divisions. But most don’t, and don’t know how, and don’t even what a UNC path is. So in order for things to go correctly, I need to use the unc path, but a user wouldn’t know what that is, they’d think it was jibberish. So I wanted to return to the user the equivalent of where things were being saved, in a manner that he’d understand.
Instead of going through all that, I’ll probably just tell some “superusers” how to do it and let the others go to them for help changing drive paths.
Cecilia
-
WSCecilia
AskWoody LoungerUrrrrgh. I hadn’t thought of that, but….
We have every drive letter mapped and then some. But that’s not really the problem, part of it is that if you do a lot of travelling, or cross-divisional work (like I do), you might have drives mapped that are 3,000 miles away across a 28.8b (or less) Wan. I’ll try it, but I’m worried that between the number of drives mapped and the potential for getting bogged down on the Wan, it’ll be really slow.
I’m hoping there’s a neater way to do it.
-
WSCecilia
AskWoody LoungerI just wrote this out for the project I’m working on….
Public Function SelectedItems(ctl As Control) As String
‘Returns an IN string for selected items in a listbox
Dim strActivities As String
Dim varItem As VariantstrActivities = “”
If ctl.ItemsSelected.Count > 0 Then
For Each varItem In ctl.ItemsSelected
strActivities = strActivities & “‘” & ctl.ItemData(varItem) & “‘,”
Next varItem
End If
SelectedItems = Left$(strActivities, Len(strActivities) – 1)
End FunctionHope this helps,
Cecilia
-
WSCecilia
AskWoody LoungerHi Charlotte,
Well, I’ve been pretty consistent about destroying objects. I’m checking the If statements now, how in depth do I need to go?
For instance, is
If IsNull(Forms!frmData.cboDivision)
okay, or do I need to change it to
If IsNull(Forms!frmData.cboDivision)=True
and similarly
If IsMissing(strDivision)
These are all over the help files.
The other one I have is If rst.NoMatch, should this be If rst.NoMatch=True?TIA!
Cecilia
-
WSCecilia
AskWoody LoungerHow about checking the characters by their chr codes?
Numbers start at chr(48) through chr(57), letters are chr(65) through chr(90) and chr(97) through (122), underscore is chr(94). You could either validate by going through each of these in a loop or use the before update to check the string.
Just an idea to make up for my dumbness earlier today
Cecilia
![]() |
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
-
Which antivirus apps and VPNs are the most secure in 2025?
by
B. Livingston
40 minutes ago -
Stay connected anywhere
by
Peter Deegan
8 hours, 25 minutes ago -
Copilot, under the table
by
Will Fastie
42 minutes ago -
The Windows experience
by
Will Fastie
5 hours, 12 minutes ago -
A tale of two operating systems
by
Susan Bradley
1 hour, 3 minutes ago -
Microsoft : Resolving Blue Screen errors in Windows
by
Alex5723
10 hours, 32 minutes ago -
Where’s the cache today?
by
Up2you2
1 day, 1 hour ago -
Ascension says recent data breach affects over 430,000 patients
by
Nibbled To Death By Ducks
18 hours, 38 minutes ago -
Nintendo Switch 2 has a remote killing switch
by
Alex5723
9 hours, 36 minutes ago -
Blocking Search (on task bar) from going to web
by
HenryW
1 day, 2 hours ago -
Windows 10: Microsoft 365 Apps will be supported up to Oct. 10 2028
by
Alex5723
1 day, 19 hours ago -
Add or Remove “Ask Copilot” Context Menu in Windows 11 and 10
by
Alex5723
1 day, 19 hours ago -
regarding april update and may update
by
heybengbeng
1 day, 20 hours ago -
MS Passkey
by
pmruzicka
22 hours, 38 minutes ago -
Can’t make Opera my default browser
by
bmeacham
2 days, 4 hours ago -
*Some settings are managed by your organization
by
rlowe44
1 day, 15 hours ago -
Formatting of “Forward”ed e-mails
by
Scott Mills
2 days, 3 hours ago -
SmartSwitch PC Updates will only be supported through the MS Store Going Forward
by
PL1
2 days, 22 hours ago -
CISA warns of hackers targeting critical oil infrastructure
by
Nibbled To Death By Ducks
3 days, 7 hours ago -
AI slop
by
Susan Bradley
1 day, 1 hour ago -
Chrome : Using AI with Enhanced Protection mode
by
Alex5723
3 days, 9 hours ago -
Two blank icons
by
CR2
17 hours, 26 minutes ago -
Documents, Pictures, Desktop on OneDrive in Windows 11
by
ThePhoenix
19 hours, 24 minutes ago -
End of 10
by
Alex5723
3 days, 20 hours ago -
Single account cannot access printer’s automatic duplex functionality
by
Bruce
2 days, 18 hours ago -
test post
by
gtd12345
4 days, 2 hours ago -
Privacy and the Real ID
by
Susan Bradley
3 days, 16 hours ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
1 day, 19 hours ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
4 days, 7 hours ago -
Upgrading from Win 10
by
WSjcgc50
2 days, 18 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.