Microsoft AccessMicrosoft OfficeMicrosoft Applications
Last Comment
rockiroads
8/22/2022 - Mon
Nate Feinberg
There is a point at which a 'compressed' code goes from elegant to confusing, and I believe you've crossed it my friend haha. I'm all for elegance, but sometimes readability has to factor into the equation. I'm not too familiar with VBA or Access VBA, I only know a bit, so I'll just kinda psuedocode it for you.
If IsDate(LastChkDt) If IsDate(Last_PO_Date) If LastChkDt > Last_PO_Date 'Use LastChkDt Else 'Use Last_PO_Date End If Else 'Use today's date End IfElse If IsDate(Last_PO_Date) 'Use Last_PO_DateElse 'Use today's dateEnd If' There are plenty of ways to shorten (and potentially optomize) this code, but this is the best way I can devise without knowing more about VBA, using redudant if conditions, or spending more time than I have at the moment. The code isn't pretty, so definitely take the time to beautify it if possible :)
if i do:
IIf(IsDate([LastChkDt])=0,IIf(IsDate([Last_PO_Date])=0,0,1),1)
i get a 0 when both of the fields are empty. i get a 1 when at least one of them is a date. i've also separated the test out into two separate columns to verify isdate() is correctly detecting when each of the two fields have a date, or when they are empty.
zephyr_hex (Megan)
ASKER
rockiroads - this solution is working...
except when both fields are null, i'm getting a date/time result for today's date.
i tried changing now() to date(), but i'm still getting date/time.
rogerard
Try using the format command to show just the mm/dd/yyyy.
i tried:
format(IIf(IsNull([dbo_qwcs_MPVEND]![LastChkDt]) And IsNull([dbo_qwcs_MPVEND]![Last_PO_Date]),date(),IIf(NZ([dbo_qwcs_MPVEND]![LastChkDt],CDate("01/01/1900"))>NZ([dbo_qwcs_MPVEND]![Last_PO_Date],CDate("01/01/1900")),[dbo_qwcs_MPVEND]![LastChkDt],[dbo_qwcs_MPVEND]![Last_PO_Date]),"mm/dd/yyyy")
and i'm still getting date/time
zephyr_hex (Megan)
ASKER
WTF?
i didn't change anything, and now it's not showing the time. just the date.
IIf(IsNull([dbo_qwcs_MPVEND]![LastChkDt]) And IsNull([dbo_qwcs_MPVEND]![Last_PO_Date]),Date(),IIf(NZ([dbo_qwcs_MPVEND]![LastChkDt],CDate("01/01/1900"))>NZ([dbo_qwcs_MPVEND]![Last_PO_Date],CDate("01/01/1900")),[dbo_qwcs_MPVEND]![LastChkDt],[dbo_qwcs_MPVEND]![Last_PO_Date]))
rogerard
That works for me in access 2010, once I added the missing parenthesis before the last comma.
format(IIf(IsNull([dbo_qwcs_MPVEND]![LastChkDt]) And IsNull([dbo_qwcs_MPVEND]![Last_PO_Date]),date(),IIf(NZ([dbo_qwcs_MPVEND]![LastChkDt],CDate("01/01/1900"))>NZ([dbo_qwcs_MPVEND]![Last_PO_Date],CDate("01/01/1900")),[dbo_qwcs_MPVEND]![LastChkDt],[dbo_qwcs_MPVEND]![Last_PO_Date])),"mm/dd/yyyy")
Sorry, I had to pop out so couldn't answer your query. I always tend to use Now() as Date() sometimes gives reference issues. Now() does give the time as you have noticed.
You have it working now anyways but an alternative to date() is DateValue(Now())
Open in new window