Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2015, 11:18 AM
Registered User
 
Join Date: Oct 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Comparing two tables with more complex criteria

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

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
 
Old October 31st, 2015, 08:22 AM
Authorized User
 
Join Date: Oct 2015
Posts: 48
Thanks: 0
Thanked 5 Times in 5 Posts
Default Comparing two tables with more complex criteria

@ SeaAnne.

I am more into MS-Excel VBA but I can already see a few issue with your code.

1. Is it TimeA or tempoA?
- tempoA is not defined.
- TimeA is defined
Code:
TimeA= TimeValue(A.Fields(2).Value)
- TempoB is defined similar to TimeA
Code:
TempoB= TimeValue(B.Fields(1).Value)
- Code that is not working:
Code:
If PainelA = PainelB And DateDiff("n", tempoA, tempoB) <= 1 Then
- What I think will work:
Code:
If PainelA = PainelB And DateDiff("n", TimeA, tempoB) <= 1 Then
2. I do not see the code that gets the corresponding [Human] field value from Table B and place it on table A, you only have a snippet that indicated a yes or no in Yes/No value
Code:
A.Fields(9).Value = Yes
To achieve what you wrote, I expected that code to have something like:
Code:
A.Fields(xx).Value = B.Fields(yy).Value
with xx/yy being the corresponding column number/Name from Tables A & B


@ [email protected]
__________________
Nostalgia 4 Infinity





Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex grouping Jayahar Crystal Reports 1 November 9th, 2009 11:26 AM
Query criteria from two tables in main connection MikeC MikeC Infopath 0 November 21st, 2007 03:16 AM
2 Tables - 1 Statement - 1 Output - 1 Criteria sencee PHP Databases 7 May 25th, 2004 04:53 AM
Comparing tables from two Databases lguzman Access VBA 1 May 11th, 2004 05:11 PM
Complex (to me) nested queries spanning 4 tables! bobburke SQL Language 1 April 23rd, 2004 10:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.