Compare data from two tables

KoskeKos

New member
Local time
Today, 18:03
Joined
May 4, 2021
Messages
28
Hi people!

I need to compare dates in two tables. TMP and VALID.
1695223513483.png
1695223522453.png

What i need is:
If date from TMP table already exist in VALID table - stop execution.
Else
Continue with code.

I know how to iterate trough tables but dont know how to set up to compare dates.

Thnx in advance.
 
Without seeing your code it is hard to advise. Do you have two recordsets open? If not you can use a Dcount to see if there is 1 or more records in the temp table matching the current record.
However I would do it the other way. I would make a query that returns only the records in TMP not in Valid. Then only work on those records.
 
Agree with MajP, I would really like to see your code. Mainly because this is a very odd way to describe the logic:

If date from TMP table already exist in VALID table - stop execution.
Else
Continue with code.

I know how to iterate...

1. Why an if/else? Why not just say--if date doesn't exist do some stuff. Why put the action in the else when you only want one branch to do things?

2. You use the words 'continue' and 'iterate' which make me think this isn't a one time test. It sounds like this is more in line with a WHILE statement not an If/Else. How many times do you expect this code to check a value? Just one value or could this test be performed for multiple values--each executing the same code if conditions are met?

Again, code clears a lot of this up.
 
Why put the action in the else when you only want one branch to do things?
Sometimes logic is easier to understand when the conditions are positive rather than negative. Not sure I would do that in this case since the negative condition seems pretty straightforward. But, there are reasons for having an empty true path.
 
DateDiff(interval, date1, date2, [ firstdayofweek, [ firstweekofyear ]] )
Last two in [ ] are optional.
d= days

dim diff as long diff = datediff (d, tablea.field, tableb.field) if diff=0 then 'same date 'do your code exit for/loop/whatever end if
 
I would make a query that returns only the records in TMP not in Valid. Then only work on those records.
Just as.

One additional point to address is that your date values have a format (final point) that is almost certainly not a valid date format. So you're dealing with text and you should take that into account.
 

Users who are viewing this thread

Back
Top Bottom