C
CB Hamlyn
**SORRY, NOT TRYING TO DOUBLE POST!
THIS JUST SEEMS LIKE A BETTER PLACE TO ASK THIS**
I have a form with three main components:
1) A listbox of employees. (this list is collected from a different form)
2) A calendar control.
3) One textbox for each day of the week.
I have a table called "Hours" that has an Employee ID, a Week ending date,
and one field for each day of a week (Sun-Sat)
Since most of the employees work 8 hours, it makes most sense to have the
supervisor go in once a day, pick the employees that were there the day
before (on a different form) type in "8" for the hours worked on the day
before, and hit apply.
The intent is to have it go through each employee on the list, then do a
search in the Hours table, checking each record to see if it matches the
Employee ID from the currently selected employee, as well as the Week Ending
Date selected on the calendar control. If it finds a match, it updates the
record with whatever hours the user put into the form, if not, it adds a new
record and inputs the data.
I had it working perfectly with Dlookup not finding a record and adding one,
but I think Dlookup isn't the way to go with finding a record and updating
it. So I'm thinking FindFirst might be the way, but how do I select the
record?
Here's what I got:
---------------------------------------------------------------------------------------------------
Dim Cntr As Integer
Dim varX As Variant
Dim strCriteria As String
Dim rstHours As ADODB.Recordset
Set rstHours = New ADODB.Recordset
rstHours.Open "Hours", CurrentProject.Connection, adOpenStatic,
adLockOptimistic
For Cntr = 0 To WED_lstEmpSel.ListCount - 1
With rstHours
strCriteria = "[HEmployeeID] = " & WED_lstEmpSel.ItemData(Cntr)
& _
" AND [HWeekEnding] = " & WED_CalWeekEndDate
.FindFirst (strCriteria)
If .NoMatch Then
.AddNew
.Fields("HEmployeeID") = WED_lstEmpSel.ItemData(Cntr)
.Fields("HWeekEnding") = WED_CalWeekEndDate
Else
'THIS IS WHERE I NEED TO SELECT THE RECORD I FOUND
End If
.Fields("HMon") = WED_txtMon
.Fields("HTue") = WED_txtTue
.Fields("HWed") = WED_txtWed
.Fields("HThu") = WED_txtThu
.Fields("HFri") = WED_txtFri
.Fields("HSat") = WED_txtSat
.Fields("HSun") = WED_txtSun
.Update
End With
Next Cntr
rstHours.Close
Set rstHours = Nothing
WED_lblFinished1.Visible = True
WED_lblFinished2.Visible = True
WED_lblFinished2.Caption = "WEEK ENDING: " & WED_CalWeekEndDate
----------------------------------------------------------------------------------------------
I'm pretty much at a loss at what even to look for in doing this. Any
guidance is highly appreciated!
Thanks
Charles Hamlyn
THIS JUST SEEMS LIKE A BETTER PLACE TO ASK THIS**
I have a form with three main components:
1) A listbox of employees. (this list is collected from a different form)
2) A calendar control.
3) One textbox for each day of the week.
I have a table called "Hours" that has an Employee ID, a Week ending date,
and one field for each day of a week (Sun-Sat)
Since most of the employees work 8 hours, it makes most sense to have the
supervisor go in once a day, pick the employees that were there the day
before (on a different form) type in "8" for the hours worked on the day
before, and hit apply.
The intent is to have it go through each employee on the list, then do a
search in the Hours table, checking each record to see if it matches the
Employee ID from the currently selected employee, as well as the Week Ending
Date selected on the calendar control. If it finds a match, it updates the
record with whatever hours the user put into the form, if not, it adds a new
record and inputs the data.
I had it working perfectly with Dlookup not finding a record and adding one,
but I think Dlookup isn't the way to go with finding a record and updating
it. So I'm thinking FindFirst might be the way, but how do I select the
record?
Here's what I got:
---------------------------------------------------------------------------------------------------
Dim Cntr As Integer
Dim varX As Variant
Dim strCriteria As String
Dim rstHours As ADODB.Recordset
Set rstHours = New ADODB.Recordset
rstHours.Open "Hours", CurrentProject.Connection, adOpenStatic,
adLockOptimistic
For Cntr = 0 To WED_lstEmpSel.ListCount - 1
With rstHours
strCriteria = "[HEmployeeID] = " & WED_lstEmpSel.ItemData(Cntr)
& _
" AND [HWeekEnding] = " & WED_CalWeekEndDate
.FindFirst (strCriteria)
If .NoMatch Then
.AddNew
.Fields("HEmployeeID") = WED_lstEmpSel.ItemData(Cntr)
.Fields("HWeekEnding") = WED_CalWeekEndDate
Else
'THIS IS WHERE I NEED TO SELECT THE RECORD I FOUND
End If
.Fields("HMon") = WED_txtMon
.Fields("HTue") = WED_txtTue
.Fields("HWed") = WED_txtWed
.Fields("HThu") = WED_txtThu
.Fields("HFri") = WED_txtFri
.Fields("HSat") = WED_txtSat
.Fields("HSun") = WED_txtSun
.Update
End With
Next Cntr
rstHours.Close
Set rstHours = Nothing
WED_lblFinished1.Visible = True
WED_lblFinished2.Visible = True
WED_lblFinished2.Caption = "WEEK ENDING: " & WED_CalWeekEndDate
----------------------------------------------------------------------------------------------
I'm pretty much at a loss at what even to look for in doing this. Any
guidance is highly appreciated!
Thanks
Charles Hamlyn