Re: Recordset or Array to memory problem
- From: "Gord" <gdt@xxxxxxxxxxxx>
- Date: 21 Mar 2007 05:01:39 -0700
On Mar 21, 2:14 am, "Kev" <kevin.vaug...@xxxxxxxxxxxxxxx> wrote:
Hello,
I have an Access 2003 database running on an XP network.
I have a datasheet subform containing a 28 day roster - shift1 to
shift28.
Each record has 1 RosterEmpID, 1 EmployeeNumber, 28 shift fields, and
1 shiftTotal field and 1 HoursTotal field.
Datasheet may look like:
Employee Shift1 Shift2 Shift3 Shift4 etc...
shiftTotal HoursTotal
Emp1 D D E
E 4 32
Emp2 D
E 2 16
Emp3 N N
N 3
30 (10hr Night shift)
The user enters shift codes into each shift field or leaves them blank
for days off. The shift codes are selected from the Shift table.
The Shift table consists of:
Table field name Example data
ShiftID D
ShiftDescription Day Shift
ShiftStartTime 07:00
ShiftEndTime 15:30
ShiftType D
ShiftPaidTime 480 (in Minutes)
I need to total the shifts and hours for each employee and am unsure
of how to
do this.
For the hours I was thinking of somehow getting the shift information
into memory without many DLookups, possibly as below. Would this place
the table information into memory where I can query it?
If so
Option Compare Database
Option Explicit
Dim db As Database
Dim RosSftrst As Recordset
Dim RosSftSQL As String 'put in form open
Dim sftID As String, sftDesc As String, sftStTime As Date, sftPdTime
As String, hrs As String
Private Sub Form_Open(Cancel As Integer)
RosSftSQL = "Select [ShiftID], [ShiftDescription], [ShiftStartTime],
[ShiftPaidTime] From RosterShifts "
Set db = CurrentDb
Set RosSftrst = db.OpenRecordset(RosSftSQL, dbOpenSnapshot)
If Not RosSftrst.EOF Then
sftID = RosSftrst![ShiftID]
sftDesc = RosSftrst![ShiftDescription]
sftStTime = RosSftrst![ShiftStartTime]
sftPdTime = RosSftrst![ShiftPaidTime]
End If
RosSftrst.Close
Set RosSftrst = Nothing
Set db = Nothing
MsgBox sftID
End Sub
Public Function HoursTot()
Dim shftHrs as string
Do until ShiftTotal
shftHrs = sftPdTime where sftID = me![Shift1] - not sure how
to do this line - IT DOESN'T WORK
hrs = hrs + shftHrs
Goto next control
Loop
Me![HoursTotal] = hrs
End Function
I would also need to convert the minutes to hours somehow. I think
I've seen this before.
Any help greatly appreciated.
Regards
Kevin
One way to keep lookup values in memory would be to use Dictionary
objects. Try this as an example:
Create a new unbound form. Add a combo box that displays the [ShiftID]
values from your [RosterShifts] table. Then create "On Load" and "On
Unload" events for the form, create an "After Update" event for the
combo box, and paste the following bits of code into each. When a new
[ShiftID] value is selected in the combo box a MsgBox will pop up
telling you what the corresponding [ShiftPaidTime] is.
'-----------------------------
Option Compare Database
Option Explicit
' this requires a reference to "Microsoft Scripting Runtime"
Dim ShiftData As Dictionary
Private Sub Combo0_AfterUpdate()
' demonstrate referencing a Dictionary of Dictionary objects
With Me.Combo0
MsgBox "ShiftPaidTime for ShiftID=""" & .Value _
& """ is " & ShiftData(.Value)("ShiftPaidTime")
End With
End Sub
Private Sub Form_Load()
Dim cdb As DAO.Database, rst As DAO.Recordset
Dim ShiftRecord As Dictionary
Set ShiftData = New Dictionary
Set cdb = CurrentDb
Set rst = cdb.OpenRecordset( _
"SELECT ShiftID, ShiftDescription, ShiftPaidTime " & _
"FROM RosterShifts", _
dbOpenSnapshot)
Do While Not rst.EOF
Set ShiftRecord = New Dictionary
With ShiftRecord
.Add "ShiftDescription", rst!ShiftDescription.Value
.Add "ShiftPaidTime", rst!ShiftPaidTime.Value
End With
ShiftData.Add rst!ShiftID.Value, ShiftRecord
Set ShiftRecord = Nothing
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set cdb = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set ShiftData = Nothing
End Sub
.
- Follow-Ups:
- Re: Recordset or Array to memory problem
- From: Kev
- Re: Recordset or Array to memory problem
- References:
- Recordset or Array to memory problem
- From: Kev
- Recordset or Array to memory problem
- Prev by Date: Re: Database only works for a week
- Next by Date: Steve Leban's RTF2 control & printing
- Previous by thread: Recordset or Array to memory problem
- Next by thread: Re: Recordset or Array to memory problem
- Index(es):
Relevant Pages
|