Bigpapou
05-29-2001, 07:36 AM
I have a group of table wich are identical in their layout but inside that layout, their data's are changing idependently from one an other. The problem now is that I want these data to be the same.
What can I do?
Is there a kind of "copy paste" proc.
What database are you using? Access, SQL, something else?
<B>Bene</B>
Bigpapou
05-29-2001, 01:48 PM
Access!
Here it is two tables: one on a computer, an other in an other computer, how can I FUSE them togeter.
Is it possible to know where the Dbs are with a proc. or something?
Tx for your help!
Probably the easiest way to do it (not the best I am sure...) is to highlight the records from one table and paste them into the other. I don't have Access loaded here, but I used to use it quite a bit and I am pretty sure that this works.
Let me know...
images/icons/cool.gif Bene
Bigpapou
05-30-2001, 07:42 AM
Yeah, it should work but with a DB as big as mine, I don't wanna check the X000 records to find those diff. every time so I'll just make myself a small function that does the work for me.
Thx anyway.
And If you have problems... just ask!
anhmytran
05-31-2001, 09:20 AM
This task can be done programmatic with ease.
1- Create 2 recordsets corresponding to each table
2- Run a loop Do While Not BRecordset.EOF and MoveNext
In each step, run a nested loop While Not ARecordset.EOF and MoveNext.
In each step of the inner loop, compare all fields of the ARecordset and BRecordset.
If ARec!Field1= BRec!Field1 AND ARec!Field2 = BRec!Field2 and so on Then
DELETE ARecordset WHERE ARec!Field1= BRec!Field1 AND ARec!Field2 = BRec!Field2 and so on
and also Exit Do Loop of the inner loop.
3- At the end of the outer loop, the ARecodset contains only records that are not
in BRecordset. You now can append all them to BRecordset by INSERT command.
AnhMy_Tran
Bigpapou
05-31-2001, 11:46 AM
I've done something like it... look(sorry for the form):
Do Until rstCar.EOF
Do Until rstMaster.EOF
egal = True
For Each fldCar In rstCar.Fields
If IsNull(rstMaster(fldCar.Name).Value) And IsNull(fldCar.Value) Then
ElseIf rstMaster(fldCar.Name).Value = fldCar.Value Then
Else
egal = False
GoTo suite
End If
Next
suite:
rstMaster.MoveNext
If egal Then
Else
If rstMaster.EOF Then
rstMaster.AddNew
For Each fldCar In rstCar.Fields
rstMaster(fldCar.Name) = fldCar.Value
Next
rstMaster.Update
End If
End If
fini:
Loop
rstMaster.MoveFirst
rstCar.MoveNext
Loop
MsgBox " Transfert terminé"
It's just, that I wanted to know if there where any other possibilitites, maybe easier.
Tx anyway.
Franck
jerryfchui
05-31-2001, 06:21 PM
I didn't examine your codes carefully but I think that is more or less we could do to achieve the job.
Another way to achieve the same is a bit manual, but it should work. If after I have tested it ok with a small set of data, I will trust it to work for me.
step1 1. create a relationship between the 2 tables.I will simply pick the first non-empty fields.
step 2. run a make table query to pick up all rcds in table 1 that are identical with table 2. The criteria of rcd selection is: all corresponding field values are the same. This generate table 3
step 3. run another query to show all rcds of table 1 that differs from table 2 or not exists in table 2. (this is outer join). Select all fields of both table 1 and 2
step 4. convert the query in step 3 to a make-table query. This is your table 4
5. there shouldn't be any problem to create 2 separate append queries. 2 rcds will be appended to table 3 from each record in table 4
The above should work but it maybe tricky when coming to empty(null) fields.
jerry
anhmytran
06-01-2001, 01:53 PM
This project need a Temporary table with the exact schema as the table Car and Maseter:
Option Explicit
Private Sub Form_Click()
Dim fldCar As Field
Dim EQL As Boolean, CarNotFound As Boolean
Dim CarNull As Boolean, MasterNull As Boolean
Dim rstCar As New ADODB.Recordset
Dim rstMaster As New ADODB.Recordset
Dim rstTemp As New ADODB.Recordset
Dim cnn As New ADODB.Connection
cnn.CursorLocation = adUseServer
cnn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=D:\CarDBase\Cars.mdb;"
' *** This block is applied for all 3 recordsets
Set rstCar = New ADODB.Recordset
rstCar.CursorLocation = adUseServer
rstCar.CursorType = adOpenStatic
rstCar.LockType = adLockOptimistic
rstCar.ActiveConnection = cnn
Set rstMaster = New ADODB.Recordset
rstMaster.CursorLocation = adUseServer
rstMaster.CursorType = adOpenStatic
rstMaster.LockType = adLockOptimistic
rstMaster.ActiveConnection = cnn
Set rstTemp = New ADODB.Recordset
rstTemp.CursorLocation = adUseServer
rstTemp.CursorType = adOpenStatic
rstTemp.LockType = adLockOptimistic
rstTemp.ActiveConnection = cnn
rstCar.Open "SELECT * FROM Cars;"
rstMaster.Open "SELECT * FROM Master;"
rstTemp.Open "DELETE * FROM Temp;"
rstTemp.Open "SELECT * FROM Temp;"
' *** The following block extracts distict records in recordset Car
' *** and store in a Temporary recordset
Do While Not rstCar.EOF
Do While Not rstMaster.EOF
EQL = True
For Each fldCar In rstCar.Fields
If Not rstMaster(fldCar.Name).Value = fldCar.Value Then
EQL = False
Exit For
End If
Next fldCar
' If they are identical, reset CarNotFound
If EQL = False Then
CarNotFound = True
Else:
CarNotFound = False
Exit Do
End If
rstMaster.MoveNext
Loop
If CarNotFound = True Then
rstTemp.AddNew
For Each fldCar In rstCar.Fields
rstTemp(fldCar.Name).Value = fldCar.Value
Next fldCar
rstTemp.Update
End If
rstCar.MoveNext
rstMaster.MoveFirst
Loop
' *** The following block appends all records in the temporary
' *** recordset to the Master Recordset
rstTemp.MoveFirst
While Not rstTemp.EOF
rstMaster.AddNew
For Each fldCar In rstMaster.Fields
rstMaster(fldCar.Name).Value = rstTemp(fldCar.Name).Value
Next fldCar
rstMaster.Update
rstTemp.MoveNext
Wend
MsgBox "Merging completed", vbInformation, "AnhMy Tran"
End
End Sub
AnhMy_Tran