reel knotty
Registered User.
- Local time
- Today, 22:30
- Joined
- Jun 5, 2002
- Messages
- 71
OK guys I have one of 2 things I am having issues figuring out. I have the following code that I would like to run in a query but having a problem changing the decleration from for to query:
Option Explicit
'*************************************************************
' FUNCTION: PrevRecVal()
' PURPOSE: Retrieve a value from a field in the previous form
' record.
' PARAMETERS:
' F - The form from which to get the previous value.
' KeyName - The name of the form's unique key field.
' KeyValue - The current record's key value.
' FieldNameToGet - The name of the field in the previous
' record from which to retrieve the value.
' RETURNS: The value in the field FieldNameToGet from the
' previous form record.
' EXAMPLE:
' =PrevRecVal(Form,"ID",[ID],"OdometerReading")
'**************************************************************
Function PrevRecVal(shipmentlookup As Form, Trans As String, KeyValue, _
Zip As String)
Dim pZip As DAO.Recordset
On Error GoTo Err_PrevRecVal
' The default value is zero.
PrevRecVal = 0
' Get the form recordset.
Set pZip = shipmentlookup.RecordsetClone
' Find the current record.
Select Case pZip.Fields(Trans).Type
' Find using numeric data type key value?
Case DB_INTEGER, DB_LONG, DB_CURRENCY, DB_SINGLE, _
DB_DOUBLE, DB_BYTE
pZip.FindFirst "[" & Trans & "] = " & KeyValue
' Find using date data type key value?
Case DB_DATE
pZip.FindFirst "[" & Trans & "] = #" & KeyValue & "#"
'Find using text data type key value?
Case DB_TEXT
pZip.FindFirst "[" & Trans & "] = '" & KeyValue & "'"
Case Else
msgBox "ERROR: Invalid key field data type!"
Exit Function
End Select
' Move to the previous record.
pZip.MovePrevious
' Return the result.
PrevRecVal = pZip(Zip)
Bye_PrevRecVal:
Exit Function
Err_PrevRecVal:
Resume Bye_PrevRecVal
End Function
Or I would like to sum the fmiles from this section of code. I have not found a "sum" function.
Public Declare Function RouteStopPairByParm Lib "batch32.dll" _
(ByVal pStop1 As String, ByVal pStop2 As String, _
ByVal pParams As String, ByVal pErrFile As String, _
ByVal pPath As String, _
ByRef pMiles As Double, _
ByRef pHours As Byte, ByRef pMins As Byte) As Byte
Public Function fmiles(pZip As String, Zip As String) As Double
Dim x As Byte
Dim miles As Double
Dim hours As Byte
Dim mins As Byte
Dim parms As String
Dim dpath As String
Dim errorfile As String
parms = "-xx -h14.0 -p"
dpath = "C:\program Files\Prophesy\Common\Tripsdb"
errorfile = "err.txt"
x = RouteStopPairByParm(pZip, Zip, parms, errorfile, dpath, miles, hours, mins)
If x = 1 Then
fmiles = miles
Else
fmiles = 0
End If
End Function
As always any and all help is greatly appreciated!!
Nate
Option Explicit
'*************************************************************
' FUNCTION: PrevRecVal()
' PURPOSE: Retrieve a value from a field in the previous form
' record.
' PARAMETERS:
' F - The form from which to get the previous value.
' KeyName - The name of the form's unique key field.
' KeyValue - The current record's key value.
' FieldNameToGet - The name of the field in the previous
' record from which to retrieve the value.
' RETURNS: The value in the field FieldNameToGet from the
' previous form record.
' EXAMPLE:
' =PrevRecVal(Form,"ID",[ID],"OdometerReading")
'**************************************************************
Function PrevRecVal(shipmentlookup As Form, Trans As String, KeyValue, _
Zip As String)
Dim pZip As DAO.Recordset
On Error GoTo Err_PrevRecVal
' The default value is zero.
PrevRecVal = 0
' Get the form recordset.
Set pZip = shipmentlookup.RecordsetClone
' Find the current record.
Select Case pZip.Fields(Trans).Type
' Find using numeric data type key value?
Case DB_INTEGER, DB_LONG, DB_CURRENCY, DB_SINGLE, _
DB_DOUBLE, DB_BYTE
pZip.FindFirst "[" & Trans & "] = " & KeyValue
' Find using date data type key value?
Case DB_DATE
pZip.FindFirst "[" & Trans & "] = #" & KeyValue & "#"
'Find using text data type key value?
Case DB_TEXT
pZip.FindFirst "[" & Trans & "] = '" & KeyValue & "'"
Case Else
msgBox "ERROR: Invalid key field data type!"
Exit Function
End Select
' Move to the previous record.
pZip.MovePrevious
' Return the result.
PrevRecVal = pZip(Zip)
Bye_PrevRecVal:
Exit Function
Err_PrevRecVal:
Resume Bye_PrevRecVal
End Function
Or I would like to sum the fmiles from this section of code. I have not found a "sum" function.
Public Declare Function RouteStopPairByParm Lib "batch32.dll" _
(ByVal pStop1 As String, ByVal pStop2 As String, _
ByVal pParams As String, ByVal pErrFile As String, _
ByVal pPath As String, _
ByRef pMiles As Double, _
ByRef pHours As Byte, ByRef pMins As Byte) As Byte
Public Function fmiles(pZip As String, Zip As String) As Double
Dim x As Byte
Dim miles As Double
Dim hours As Byte
Dim mins As Byte
Dim parms As String
Dim dpath As String
Dim errorfile As String
parms = "-xx -h14.0 -p"
dpath = "C:\program Files\Prophesy\Common\Tripsdb"
errorfile = "err.txt"
x = RouteStopPairByParm(pZip, Zip, parms, errorfile, dpath, miles, hours, mins)
If x = 1 Then
fmiles = miles
Else
fmiles = 0
End If
End Function
As always any and all help is greatly appreciated!!
Nate