Stang70Fastback
Registered User.
- Local time
- Today, 06:01
- Joined
- Dec 24, 2012
- Messages
- 132
Hello all. Here is another issue I'm having. I have the following in query form:
I realize it's a bit "messy" in how it does what it is doing, but it works. Can someone explain to me why that works perfectly fine when I build a Query in Access, but why this version returns NO records when I try to use it to set a form's recordsource via VBA code?
Both run without errors, but one returns 4 records as it is supposed to (the top one, formed as an actual query) whereas the bottom one returns NO records.
I actually built the top one FROM the bottom one to test it as a proper query when I couldn't get it to work, and after removing the various single and double quotes, it simply worked, so I'm at a loss as to why the original one is giving me different, and incorrect, results.
Yes, I know I could just set the QUERY as the RecordSource at this point, but I'm trying to be consistent with my code, and not have one random one that points to an Access Query.
Code:
SELECT *
FROM Timesheets
WHERE Nz(DLookup("Username", "USER", "Badge = " & Nz(DLookup("Manager", "Engineers", "Badge = " & [Badge]), 0)), "NoResult") = fOSUserName();
I realize it's a bit "messy" in how it does what it is doing, but it works. Can someone explain to me why that works perfectly fine when I build a Query in Access, but why this version returns NO records when I try to use it to set a form's recordsource via VBA code?
Code:
Me.RecordSource = "SELECT * FROM Timesheets WHERE '" & Nz(DLookup("Username", "USER", "Badge = " & Nz(DLookup("Manager", "Engineers", "Badge = " & [Badge]), 0)), "NoResult") & "' = '" & fOSUserName & "'"
Both run without errors, but one returns 4 records as it is supposed to (the top one, formed as an actual query) whereas the bottom one returns NO records.
I actually built the top one FROM the bottom one to test it as a proper query when I couldn't get it to work, and after removing the various single and double quotes, it simply worked, so I'm at a loss as to why the original one is giving me different, and incorrect, results.
Yes, I know I could just set the QUERY as the RecordSource at this point, but I'm trying to be consistent with my code, and not have one random one that points to an Access Query.
Last edited: