krymat
Technical User
- Jul 25, 2000
- 105
Function EfficParm(ParmType As String, processname As String, MachineType As String, Machine As String, proddate As Date)
Dim dbs As DATABASE, rst As Recordset, RecCount As Integer, PType As Integer
Set dbs = CurrentDb
Select Case ParmType
Case "upt"
PType = 4
Case "utilhrs"
PType = 5
Case "unitcount"
PType = 6
Case "goal"
PType = 7
Case Else
PType = 0
Exit Function
End Select
Select Case MachineType
Case "none"
strSQL = "SELECT * FROM tblAccounting_EfficParms WHERE [processname] = '" & processname & "' And [machine] = '" & Machine & "' ORDER BY [effec_date]"
Case Else
strSQL = "SELECT * FROM tblAccounting_EfficParms WHERE [processname] = '" & processname & "' And [machine] = '" & Machine & "' And [machinetype] = '" & MachineType & "' ORDER BY [effec_date]"
End Select
Set rst = dbs.OpenRecordset(strSQL)
RecCount = rst.RecordCount
Select Case RecCount
Case 0
rst.Close
Case 1
EfficParm = rst.Fields(PType).Value
Case Else
rst.MoveLast
If rst.Fields(9).Value < proddate Then
EfficParm = rst.Fields(PType).Value
rst.Close
Exit Function
Else
rst.MoveFirst
End If
Do While Not rst.EOF
If rst.Fields(9).Value = proddate Then
EfficParm = rst.Fields(PType).Value
rst.Close
Exit Function
ElseIf rst.Fields(9).Value < proddate Then
rst.MoveNext
ElseIf rst.Fields(9).Value > proddate Then
rst.MovePrevious
EfficParm = rst.Fields(PType).Value
rst.Close
Exit Function
End If
Loop
End Select
End Function
This is what I came up with to deal with an effective date in dealing with machine efficiencies. Is what I'm doing here look correct, or could there be a way to make it better?
Dim dbs As DATABASE, rst As Recordset, RecCount As Integer, PType As Integer
Set dbs = CurrentDb
Select Case ParmType
Case "upt"
PType = 4
Case "utilhrs"
PType = 5
Case "unitcount"
PType = 6
Case "goal"
PType = 7
Case Else
PType = 0
Exit Function
End Select
Select Case MachineType
Case "none"
strSQL = "SELECT * FROM tblAccounting_EfficParms WHERE [processname] = '" & processname & "' And [machine] = '" & Machine & "' ORDER BY [effec_date]"
Case Else
strSQL = "SELECT * FROM tblAccounting_EfficParms WHERE [processname] = '" & processname & "' And [machine] = '" & Machine & "' And [machinetype] = '" & MachineType & "' ORDER BY [effec_date]"
End Select
Set rst = dbs.OpenRecordset(strSQL)
RecCount = rst.RecordCount
Select Case RecCount
Case 0
rst.Close
Case 1
EfficParm = rst.Fields(PType).Value
Case Else
rst.MoveLast
If rst.Fields(9).Value < proddate Then
EfficParm = rst.Fields(PType).Value
rst.Close
Exit Function
Else
rst.MoveFirst
End If
Do While Not rst.EOF
If rst.Fields(9).Value = proddate Then
EfficParm = rst.Fields(PType).Value
rst.Close
Exit Function
ElseIf rst.Fields(9).Value < proddate Then
rst.MoveNext
ElseIf rst.Fields(9).Value > proddate Then
rst.MovePrevious
EfficParm = rst.Fields(PType).Value
rst.Close
Exit Function
End If
Loop
End Select
End Function
This is what I came up with to deal with an effective date in dealing with machine efficiencies. Is what I'm doing here look correct, or could there be a way to make it better?