compare dates? (1 Viewer)

vicsaccess

New member
Local time
Today, 12:15
Joined
Jul 17, 2015
Messages
7
can I create a macro that will use the date on a form and compare it to a list of dates in a table and if yes perform an operation?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 18:15
Joined
Jul 9, 2003
Messages
16,272
I wouldn't know if it is possible with a macro, however it is definitely possible with VBA code.
 

MSAccessRookie

AWF VIP
Local time
Today, 13:15
Joined
May 2, 2008
Messages
3,428
can I create a macro that will use the date on a form and compare it to a list of dates in a table and if yes perform an operation?

Knowing absolutely NOTHING about your Database, it is hart to be specific, but when you break down your question into smaller pieces, it seems to answer itself. As you can see, the answer should be Yes.

-- Rookie
Code:
Can I create a macro that will (under most normal circumstances):
  
[LIST] 
[*]Use the date on a form.  [B]Yes.[/B] The Control on the Form has a name that the Macro can use to find the value.
[*]Compare the date on the form to a list of dates in a table.  [B]Yes.[/B] An SQL Query Comes in handy for doing this.
[*]Perform an operation when there is a match.  [B]Yes, [/B]but that also depends on whether or not a Macro can perform the required operation.
[/LIST]
 

vicsaccess

New member
Local time
Today, 12:15
Joined
Jul 17, 2015
Messages
7
Thank you both. I had not thought of using a query. I'll try tonight and get back to you.
 

George21

Registered User.
Local time
Today, 20:15
Joined
Jan 10, 2011
Messages
26
You may use VBA.

Set db = CurrentDb

Set rs = db.OpenRecordset("YourTableName")

If Not (rs.EOF And rs.BOF) Then

rs.MoveFirst

Do Until rs.EOF = True

If rs("DateNameInTable") = Me.DateNameInForm Then
.....................
.....................
End If

rs.MoveNext

Loop
End If


Note:
"YourTableName" refers to the name of the table you want to look up the dates.
"YourTableName" refers to the name of this the field the dates are stored in the table.
Me.DateNameInForm refers to the name of the text box where the date is in the form. We assume that this code will be stored in the same Forms module.
 

Users who are viewing this thread

Top Bottom