kfschaefer
Registered User.
- Local time
- Today, 03:12
- Joined
- Oct 10, 2008
- Messages
- 58
I need to compare two tables, data and determine differences and where different - update the first table with the new data. I am looking for the best approach - a simple update query will not sufficient due to the fact the second record set is not an updatable query, hence the need to use the recordset method.
The issue is with field name and field value, what is the proper syntax for the See:
Problem is with object not found, even though the hover over the rs1(f.value) does display a value. Not sure where I am going wrong:
rs(F.value) = rs1(F.value)
'------------------------------------------------------------------------------------------------
Thanks,
Karen
The issue is with field name and field value, what is the proper syntax for the See:
Problem is with object not found, even though the hover over the rs1(f.value) does display a value. Not sure where I am going wrong:
rs(F.value) = rs1(F.value)
'------------------------------------------------------------------------------------------------
Code:
Private Sub cmdValidateGeneralInfo_Click()
On Error GoTo Err_cmdValidateGeneralInfo_Click
Dim stDocName As String
Dim F As DAO.Field
Dim nName As DAO.Fields
Dim rs As DAO.Recordset
Dim rs1 As DAO.Recordset
Set curDB = CurrentDb()
If Me.DateModified = Date Then
'Adds new employees to the TT_GeneralInfo table in the FTEI_PhoneBook.mdb - which is used thru out the AP databases.
DoCmd.OpenQuery "qryEmpData_TT_General"
strSQL = "SELECT Name, LastName, FirstName, MidName, PrfName, BEMS, NT_UserId," & _
" StableEmail, WrkPhNo, WrkPhNo2, PagerPh, Org, MS, Bldg, Cub, AltBldg, AltCub, RevDt, EmplClass" & _
" FROM TT_GeneralInfo"
Set rs = curDB.OpenRecordset(strSQL)
strSQL1 = "SELECT [LastName] & ', ' & Left([FirstName],1) & '.' & IIf(IsNull([Midname]),'',Left([MidName],1) & '. ') & IIf(IsNull([PrfName]),'','(' & [PrfName] & ')') AS Name," & _
" LastName, FirstName, MidName, PrfName," & _
" BEMS, NT_UserId, StableEmail, WrkPhNo, WrkPhNo2, PagerPh, tblOrgListing_lkup.Org, MailStop as MS, Bldg_Primary as Bldg," & _
" Col_Cub_Primary as Cub, Bldg_Alt as AltBldg, Col_Cub_Alt as AltCub, Date() AS RevDt, tblEmplClass_lkup.EmplClass" & _
" FROM (tblEmployee LEFT JOIN tblEmplClass_lkup ON tblEmployee.ClassCtr = tblEmplClass_lkup.ClassCtr) LEFT JOIN tblOrgListing_lkup ON tblEmployee.Mgr_OrgNo = tblOrgListing_lkup.OrgCtr" & _
" WHERE (((tblOrgListing_lkup.UpdateGeneralInfo)=-1) AND ((tblEmployee.Active)=-1))"
Set rs1 = curDB.OpenRecordset(strSQL1)
While Not rs1.EOF
For Each F In rs1.Fields
If F.value <> rs(F.Name) Then
rs.Edit
'Set nName = rs1(F.value)
rs(F.value) = rs1(F.value)
rs.Update
End If
Next F
rs.Close
rs1.MoveNext
Wend
rs1.Close
End If
stDocName = "QS_EMD_tblEmployee vs TT_GeneralInfo"
DoCmd.OpenQuery stDocName, acNormal, acReadOnly
Exit_cmdValidateGeneralInfo_Click:
Exit Sub
Err_cmdValidateGeneralInfo_Click:
MsgBox Err.Description
Resume Exit_cmdValidateGeneralInfo_Click
On Error GoTo 0
Exit Sub
cmdValidateGeneralInfo_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdValidateGeneralInfo_Click of VBA Document Form_frmEmpMain"
End Sub
Thanks,
Karen