Comparing two tables with specfic criteria

mfaqueiroz

New Member
Joined
Sep 30, 2015
Messages
5
Hi,

I'm comparing two tables, A and B. I want when Painel it's the same in both tables and the difference of the time it's less then one minute give me the value of field [human] that belong to B table, and writes this value in my A table.
I wrote the following code, but isn't working... ..could you please help me!
I'm stuck
banginghead.gif


I really appreciate your dedication and time!



Private Sub OrdLigDesl()

Dim y As Integer
Dim x As Integer
Dim TempoLigDesl As Date
Dim TempoEvenLog As Date

Set dbs = DBEngine(0)(0)
Set A= dbs.OpenRecordset("A", DB_OPEN_TABLE)
Set B= dbs.OpenRecordset("B", DB_OPEN_TABLE)

contaA = DCount("[Painel]", "A")
contaB= DCount("[Painel]", "B")
x = 0
y = 0


A.MoveFirst


For y = 1 To contaA
TimeA= TimeValue(A.Fields(2).Value)
PainelA= A.Fields(5).Value


B.MoveFirst

For x = 1 To contaB

TempoB= TimeValue(B.Fields(1).Value)
PainelB = B.Fields(7).Value
Human = B.Fields(4).Value


If PainelA = PainelB And DateDiff("n", tempoA, tempoB) <= 1 Then

A.Edit
A.Fields(9).Value = Yes
A.Update



Else

End If
B.MoveNext

Next x
A.MoveNext
Next y


End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
First, "it's not working" is of no help to anyone. That could mean just about anything.
Then, there's too much wrong with this code (if that's all there is that's relevevant) to even begin. Why can you not just do this with a query by joining A and B on the field that contains "Painel", use that text for its criteria, include both time fields, have a field (TimeDiff) that calculates the difference and include criteria for the duration (one minute) and include the field that contains [human]. Once you get that right, turn it into an update query (assuming you already have a record in the target table that you want to update) or if not, an append query.
 
Upvote 0

Forum statistics

Threads
1,221,834
Messages
6,162,268
Members
451,758
Latest member
lmcquade91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top