Compare data from two tables (1 Viewer)

KoskeKos

New member
Local time
Today, 17:42
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:42
Joined
May 21, 2018
Messages
8,529
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.
 

plog

Banishment Pending
Local time
Today, 10:42
Joined
May 11, 2011
Messages
11,646
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:42
Joined
Feb 19, 2002
Messages
43,275
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.
 

mikem_uk

New member
Local time
Today, 16:42
Joined
Sep 21, 2023
Messages
1
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
 

ebs17

Well-known member
Local time
Today, 17:42
Joined
Feb 7, 2020
Messages
1,946
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

Top Bottom