Reference a Table Field Value

  • Thread starter Thread starter Stephen sjw_ost
  • Start date Start date
S

Stephen sjw_ost

Hello again. Thank you for all of the help in the past!

I have another question I need help with please.

How can I write code to check a table for todays date and then perform an
action.
My table, t_Date, only has 1 field, uDate, formated as Date/Time and the
field is the primary key to prevent duplicates. I am looking to do something
like;

If t_Date.uDate = Date Then
MsgBox "STOP"
End If

The uDate field will be added to everyday with "today's" date so there will
be multiple date entries.

Can someone help me with this please?
I'm sure it is simple but I just can't seem to figure it out.
Thanks again.
 
I answered my own question.
I wanted to be able to update the table with todays date and then use the
date in the table to prevent the code from running. I had the first part and
figured out the last. Here is the answer I came up with.

Function Test()
Dim myDt
Dim myUdt
myDt = Date
myUdt = DLookup("[uDate]", "t_Date")
CurrentDb.Execute "INSERT INTO t_Date( uDate) " & _
"SELECT '" & myDt & "' as uDate;"
If myUdt = Date Then
MsgBox "STOP"
End If
End Function

I hope this can help someone else.
Thanks for all of the past help and any replies.
 
Stephen, you might want to use the DMAX function instead of DLOOKUP
because there is no guarantee DLOOKUP will return the most recent date
in your table. If you want to know the last time some event ran, for
example, this might be important. DMAX works pretty much the same way
(same criteria in this case).

Richard Rost
http://www.AccessLearningZone.com?key=usenet
 
Amicron, thank you for your response.

Will DMAX really matter over DLOOKUP when I am ultimately compairing the
DLOOKUP to Date()? So if any date in the table equals Date() then show my
message.

myUdt = DLookup("[uDate]", "t_Date")
If myUdt = Date Then
MsgBox "STOP"
End If

I want to be sure this will continue to work with what I have or if your
suggestion is a better route.
 
Back
Top