kfschaefer
Registered User.
- Local time
- Today, 08:05
- Joined
- Oct 10, 2008
- Messages
- 58
I am attempting to update data in a table comparing the field names of temptable1 to the data in the temptable2.
I have tried several renditions of a Do loop statement and neither return the correct results.
I need to compare the BEMS(EmployeeNo) in both tables. Table1 = Has the fieldNames(Course No), ie. Field1.name =GLW0029,
Field2.name =74735
Field3.name =80808, etc.....
the beginning fields in this table are
UCBEMS, Org, MgrName, EmployeeName, BEMS & PercentCompleteByName,
Hence the for i = 6 to j portion of the code.
Table2 contains fields
BEMS, [Ilp Learning Cd], CompDt FROM qryEmpMgrCourseList from a query1
I need to match the data in [Ilp Learning Cd] with the fieldnames in table1 to insert, CompDt (completionDate)
in each of the appropriate fields in table1.
I know I only need 1 of the Do Loops, or combination of .
So if table1.BEMS =Table2.BEMS then
Do this
Table1.fieldName("GLW0029") = table2.[Ilp Learning Cd].value =GLW0029 then
insert the CompDt = 12/1/2010 into Table1.Fieldname("GLW0029")
Please help me to clean up this code?
I have tried several renditions of a Do loop statement and neither return the correct results.
I need to compare the BEMS(EmployeeNo) in both tables. Table1 = Has the fieldNames(Course No), ie. Field1.name =GLW0029,
Field2.name =74735
Field3.name =80808, etc.....
the beginning fields in this table are
UCBEMS, Org, MgrName, EmployeeName, BEMS & PercentCompleteByName,
Hence the for i = 6 to j portion of the code.
Table2 contains fields
BEMS, [Ilp Learning Cd], CompDt FROM qryEmpMgrCourseList from a query1
I need to match the data in [Ilp Learning Cd] with the fieldnames in table1 to insert, CompDt (completionDate)
in each of the appropriate fields in table1.
I know I only need 1 of the Do Loops, or combination of .
So if table1.BEMS =Table2.BEMS then
Do this
Table1.fieldName("GLW0029") = table2.[Ilp Learning Cd].value =GLW0029 then
insert the CompDt = 12/1/2010 into Table1.Fieldname("GLW0029")
Please help me to clean up this code?
Code:
Public Sub FillInData()
'On Error GoTo ProcError
'Purpose: Fill-in the Course Completion Dates for each employee record in the temporary linked table (tblZTemp)
Dim rs1 As DAO.Recordset 'Temporary work table: tblZTemp
Dim rs2 As DAO.Recordset 'qryEmpMgrCourseList
Dim fld As DAO.Field
Dim i As Integer
Dim j As Integer 'Used to store a count of how many courses are in rs1 (zTempData)
Dim strSQL As String
Dim strSQL2 As String
strSQL = "INSERT INTO Ztempdata ( UCBEMS, Org, MgrName, EmployeeName, BEMS, PercentCompleteByName )" & _
" SELECT qryEmpMgrCourseList.UCBEMS, qryEmployeeManager.Org, qryEmployeeManager.MgrName," & _
" qryEmpMgrCourseList.EmployeeName, qryEmpMgrCourseList.BEMS, qryEmpMgrCourseList.Pct" & _
" FROM qryEmpMgrCourseList INNER JOIN qryEmployeeManager ON" & _
" qryEmpMgrCourseList.Mgr_OrgNo = qryEmployeeManager.OrgCtr" & _
" GROUP BY qryEmpMgrCourseList.UCBEMS, qryEmployeeManager.Org, qryEmployeeManager.MgrName," & _
" qryEmpMgrCourseList.EmployeeName, qryEmpMgrCourseList.BEMS, qryEmpMgrCourseList.Pct"
CurrentDb.Execute (strSQL)
If IsTableExist("tblZTemp") Then
DoCmd.DeleteObject acTable, "tblZTemp"
End If
strSQL = "SELECT * FROM ztempdata ORDER BY BEMS"
Set rs1 = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
'We subtract 1 because field references are "zero-based".
j = rs1.Fields.Count - 1
If rs1.RecordCount = 0 Then
MsgBox "There are no required courses for current employees to process.", vbInformation, "No Records To Process..."
'GoTo ExitProc
End If
'List of Employee and Course numbers where New Hire rules apply - Code to insert NH instead of a date
strSQL2 = "SELECT BEMS, [Ilp Learning Cd], CompDt FROM qryEmpMgrCourseList ORDER BY BEMS, [Ilp Learning Cd]"
' Debug.Print strSQL2
Set rs2 = CurrentDb.OpenRecordset(strSQL2, dbOpenSnapshot)
'Check field values in tblZtemp (rs1). This recordset includes a dynamic number of fields.
'The first six fields, fields 0-6, are constant: UCBEMS, Org, MgrName, EmployeeName, BEMS & PercentCompleteByName
Do Until rs2.EOF
rs1.MoveFirst
If rs1.Fields("BEMS") = rs2.Fields("BEMS") Then
For i = 6 To j
If rs1(i).Name = rs2("[Ilp Learning Cd]") Then
rs1.Edit
rs1(i) = rs2.Fields("CompDt")
rs1.Update
Exit For
End If
Next i
End If
rs2.MoveNext
' Loop
rs1.MoveNext
Loop
Do Until rs1.EOF
rs2.MoveFirst
Do Until rs2.EOF
If rs1("BEMS") = rs2("BEMS") Then
For i = 6 To j
If rs1(i).Name = rs2("[Ilp Learning Cd]") Then
rs1.Edit
rs1(i) = rs2.Fields("CompDt")
rs1.Update
Exit For
End If
Next i
End If
rs2.MoveNext
Loop
rs1.MoveNext
Loop
'ExitProc:
''Cleanup
' On Error Resume Next
' rs1.Close: Set rs1 = Nothing
' rs2.Close: Set rs2 = Nothing
' Exit Sub
'
'ProcError:
' If Err.Number = 3021 Then
' Err.Clear
' Resume Next
' Else
' MsgBox "Error " & Err.Number & ": " & Err.Description, _
' vbCritical, "Error in procedure FillInData..."
' Resume Next
' Resume
' End If
End Sub