cenderawasih
MIS
Hi,
I need to copy data from one table into another table and manage to do this if the destination table is blanks.When the destination table is not blank anymore(contains the first time copied data from the main table), then I want to add new data in the main table into the destination table, my coding gives me errors.
What the codes should do is to check for data in the main table and the data in the destination table, the matching data should be left alone, but when it found an unmatch data in the main table with the destination table (meaning the data exist in the main table but not yet copied/didn't exist in the destination table) then these data (in the main table) should be copied/add to the destination table...
Here is my code:
Private Sub Form_Load()
Dim cnn As New ADODB.Connection
Dim rstFPT1JP00 As New ADODB.Recordset
Dim rstTemp As New ADODB.Recordset
Dim strFPTIJP00 As String
Dim strTemp As String
Dim strCriteria As String
Set cnn = CurrentProject.Connection
strFPT1JP00 = "SELECT PTMCU,PTDIV,PTDFS,PTDTS,PTABNO,PTNAME,PTSTS,PTDFM,PTDTM,PTDCO FROM SRPRJTRAK_FPT1JP00"
strTemp = "SELECT tempPTMCU,tempPTDFS,tempPTDTS,tempPTDFM,tempPTDTM,tempPTDCO FROM TblTempDate"
strCriteria = tempPTMCU = PTMCU
'OPEN MAIN TABLE
With rstFPT1JP00
Set .ActiveConnection = cnn
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open strFPT1JP00
.MoveFirst
'OPEN DESTINATION TABLE
With rstTemp
Set .ActiveConnection = cnn
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open strTemp
'THIS PART ALSO DIDN'T WORK, IT SEEMS THAT WHETHER THE DESTINATION TABLE IS BLANK(HAVE NO VALUE) OR NOT BLANK (HAVE VALUE) THE RECORDCOUNT WITH ALWAYS EQUAL TO -1. THE CODES BELOW SHOULD RUN IF THE SYSTEM FOUND THAT THE RECORDCOUNT FOR DESTINATION TABLE=0 (DESTINATION TABLE IS BLANKS)
If rstTemp.RecordCount = 0 Then
Do Until rstFPT1JP00.EOF
rstTemp.AddNew
rstTemp.Fields("tempPTMCU" = rstFPT1JP00.Fields
("PTMCU".Value
rstFPT1JP00.MoveNext
Loop
'WHEN THE DESTINATION TABLE IS NOT BLANK, THEN THIS CODE WILL BE RAN. ANYWAY THE FIND COMMAND AND THE NOMATCH COMMAND GIVES ME THIS ERROR MSG:"method or data member not found".
Else
rstTemp.FindFirst strCriteria
If rstTemp.NoMatch = False Then
rstTemp.MoveLast
Do Until rstFPT1JP00.EOF
rstTemp.AddNew
rstTemp.Fields("tempPTMCU" = rstFPT1JP00.Fields
("PTMCU".Value
rstFPT1JP00.MoveNext
Loop
End If
End If
End With
End With
rstFPT1JP00.Close
Me.Requery
End Sub
FOR UR INFORMATION I HAVE TICK THE REFERENCE FOR DAO OBJECT.
CAN ANYONE HELP ME WITH THIS ONE?
I need to copy data from one table into another table and manage to do this if the destination table is blanks.When the destination table is not blank anymore(contains the first time copied data from the main table), then I want to add new data in the main table into the destination table, my coding gives me errors.
What the codes should do is to check for data in the main table and the data in the destination table, the matching data should be left alone, but when it found an unmatch data in the main table with the destination table (meaning the data exist in the main table but not yet copied/didn't exist in the destination table) then these data (in the main table) should be copied/add to the destination table...
Here is my code:
Private Sub Form_Load()
Dim cnn As New ADODB.Connection
Dim rstFPT1JP00 As New ADODB.Recordset
Dim rstTemp As New ADODB.Recordset
Dim strFPTIJP00 As String
Dim strTemp As String
Dim strCriteria As String
Set cnn = CurrentProject.Connection
strFPT1JP00 = "SELECT PTMCU,PTDIV,PTDFS,PTDTS,PTABNO,PTNAME,PTSTS,PTDFM,PTDTM,PTDCO FROM SRPRJTRAK_FPT1JP00"
strTemp = "SELECT tempPTMCU,tempPTDFS,tempPTDTS,tempPTDFM,tempPTDTM,tempPTDCO FROM TblTempDate"
strCriteria = tempPTMCU = PTMCU
'OPEN MAIN TABLE
With rstFPT1JP00
Set .ActiveConnection = cnn
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open strFPT1JP00
.MoveFirst
'OPEN DESTINATION TABLE
With rstTemp
Set .ActiveConnection = cnn
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open strTemp
'THIS PART ALSO DIDN'T WORK, IT SEEMS THAT WHETHER THE DESTINATION TABLE IS BLANK(HAVE NO VALUE) OR NOT BLANK (HAVE VALUE) THE RECORDCOUNT WITH ALWAYS EQUAL TO -1. THE CODES BELOW SHOULD RUN IF THE SYSTEM FOUND THAT THE RECORDCOUNT FOR DESTINATION TABLE=0 (DESTINATION TABLE IS BLANKS)
If rstTemp.RecordCount = 0 Then
Do Until rstFPT1JP00.EOF
rstTemp.AddNew
rstTemp.Fields("tempPTMCU" = rstFPT1JP00.Fields
("PTMCU".Value
rstFPT1JP00.MoveNext
Loop
'WHEN THE DESTINATION TABLE IS NOT BLANK, THEN THIS CODE WILL BE RAN. ANYWAY THE FIND COMMAND AND THE NOMATCH COMMAND GIVES ME THIS ERROR MSG:"method or data member not found".
Else
rstTemp.FindFirst strCriteria
If rstTemp.NoMatch = False Then
rstTemp.MoveLast
Do Until rstFPT1JP00.EOF
rstTemp.AddNew
rstTemp.Fields("tempPTMCU" = rstFPT1JP00.Fields
("PTMCU".Value
rstFPT1JP00.MoveNext
Loop
End If
End If
End With
End With
rstFPT1JP00.Close
Me.Requery
End Sub
FOR UR INFORMATION I HAVE TICK THE REFERENCE FOR DAO OBJECT.
CAN ANYONE HELP ME WITH THIS ONE?