Solved Compare Two date values in two fields in one table

mansied

Member
Local time
Today, 00:01
Joined
Oct 15, 2020
Messages
100
Hello
I have a basic question,
I have a table and want to compare dates .if date 1> date 2 , then pop a message .
any Idea how can i do it ?
with query or with VBA ??
Thank you
 
Hi. Tables could have more than one record. How do you determine which records to compare?
 
Hi. Tables could have more than one record. How do you determine which records to compare?
it is better to check all records .but if it could find the first one should pop a message..I really just need the notice to pop out .
 
it is better to check all records .but if it could find the first one should pop a message..I really just need the notice to pop out .
Maybe you can give us some sample data to help us understand what you need. If there are multiple dates in both tables, you will inevitably get the popup.
 
I have this code to import from Xl to Access records by record . how can i add a control here ?

For Each varFile In .SelectedItems
Name = varFile
FileName = Dir(varFile)
Workbooks.Open(varFile).Sheets("Report Details").Activate
Dim i As Integer
i = Cells(Rows.Count, 1).End(xlUp).Row
ActiveWorkbook.Close False
i = i - 1
DoCmd.RunSQL ("INSERT INTO ImportedRows (Rows) VALUES ('" & i & "');")

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "DATA_DA_Imported", varFile, True, "Report Details!"
 
One table with two date fields .if return to service date < event occurrence , then pop a messag
1633616195314.png
e
 

Attachments

  • 1633615974368.png
    1633615974368.png
    8.3 KB · Views: 178
One table with two date fields .if return to service date < event occurrence , then pop a messagView attachment 95092e
Ah, so you're not trying to compare two tables then. Instead, you just want to compare two columns in one table, and all the records have the same dates, correct? If so, you should be able to use DLookup().
 
Ah, so you're not trying to compare two tables then. Instead, you just want to compare two columns in one table, and all the records have the same dates, correct? If so, you should be able to use DLookup().
yes two fields in one table ....
 
yes two fields in one table ....
So, did you try using DLookup()? For example:

Code:
If DLookup("[Return to Service Date]<[Event Occurrence]", "TableName")=True Then
    Msgbox "Popup message here."
End If
 
So, did you try using DLookup()? For example:

Code:
If DLookup("[Return to Service Date]<[Event Occurrence]", "TableName")=True Then
    Msgbox "Popup message here."
End If
Yes i tested .It doesn't work .i have no error on it but no message pops...
 
Yes i tested .It doesn't work .i have no error on it but no message pops...
Are those date columns actually Date/Time data types? Or, are they Short Text?
 
I have a table and want to compare dates .if date 1> date 2 , then pop a message .
Are you wanting to get that message box at the time data is entered in for a record? If so, then that code would go into a Before Update event. That's usually how I would set something like that up. This prevents bad data from going into the table in the first place.
 
Are you wanting to get that message box at the time data is entered in for a record? If so, then that code would go into a Before Update event. That's usually how I would set something like that up. This prevents bad data from going into the table in the first place.
Yes ,update events ? what do mean .?

this part of code is useded to import ..


For Each varFile In .SelectedItems
Name = varFile
FileName = Dir(varFile)
Workbooks.Open(varFile).Sheets("Report Details").Activate
Dim i As Integer
i = Cells(Rows.Count, 1).End(xlUp).Row
ActiveWorkbook.Close False
i = i - 1
DoCmd.RunSQL ("INSERT INTO ImportedRows (Rows) VALUES ('" & i & "');")

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "DATA_DA_Imported", varFile, True, "Report Details!"
 
yes both are Date/Time data types.
In that case, try the following code and let us know if the result makes sense.
Code:
If DLookup("[Return to Service Date]<[Event Occurrence]", "TableName")=True Then
    MsgBox "Popup message here."
Else
    MsgBox DLookup("[Return to Service Date]", "TableName") _
        & " is not lesser/earlier than " & DLookup("[Event Occurrence]", "TableName")
End If
 
In that case, try the following code and let us know if the result makes sense.
Code:
If DLookup("[Return to Service Date]<[Event Occurrence]", "TableName")=True Then
    MsgBox "Popup message here."
Else
    MsgBox DLookup("[Return to Service Date]", "TableName") _
        & " is not lesser/earlier than " & DLookup("[Event Occurrence]", "TableName")
End If
Thank you very much.it worked properly .:)
 

Users who are viewing this thread

Back
Top Bottom