R
RayC
Just trying to find out if I am writing my code in the correct way. The Block
should be self explanitory but is there a better way to write it?
Public Function util_GetNewContractNo(a As Long) As Long
'*****************************************************************=**********************
' Name: util_GetNewContractNo :- Utility Number 2
' Purpose: Store and increment the next Contract Number
'
' Returns: Long
'
' Author:
' Date: August 07, 2006
' Comment: Stores the current Contract No and returns an incremented Number
if required
' This function works with the Table "const_tbl_NewContractNo" to find the
next Contract No
' in the sequence; retreive it, increment it and write out the new
next contract no.
' If the function receives a 0 or a Null from the calling routine, it will
return the
' stored Contract No.
' If it receives a valid Contract No from the calling routine, it will
incement the number and
' store the next incremented number in the Table ready for the next use.
'*****************************************************************=**********************
On Error GoTo Err_GetNewContractNo
Dim dbs As Database, rs88 As Recordset, a As Long
Set dbs = CurrentDb
Set rs86 = dbs.OpenRecordset("const_tbl_NewContractNo", dbOpenDynaset)
' Get last Contract Number from "const_tbl_NewContractNo", increment it and
return.
rs86.MoveLast
If a = 0 Or a = Null Then
util_GetNewContractNo = rs86("ContractNo") ' return the Contract
No stored in the Table
ElseIf a = rs86("ContractNo") Then
rs86.MoveLast: rs86.Edit
rs86("ContractNo") = a + 1 ' Save incremented last Contract No
in "NewContractNo"
rs86.Update
util_GetNewContractNo = rs86("ContractNo") ' return the Contract
No stored in the Table
Else
MsgBox "Error you don't have the correct Contract Number",
vbOKOnly, "ERROR"
util_GetNewContractNo = 0 ' return 0 to
signify the error
End If
Exit_GetNewContractNo:
rs86.Close: dbs.Close
Exit Function
Err_GetNewContractNo:
Select Case Err
Case 0
Case Else
MsgBox Err.Description
Resume Exit_GetNewContractNo
End Select
End Function
Thanks for any pointers to get me in the right direction.
RayC
should be self explanitory but is there a better way to write it?
Public Function util_GetNewContractNo(a As Long) As Long
'*****************************************************************=**********************
' Name: util_GetNewContractNo :- Utility Number 2
' Purpose: Store and increment the next Contract Number
'
' Returns: Long
'
' Author:
' Date: August 07, 2006
' Comment: Stores the current Contract No and returns an incremented Number
if required
' This function works with the Table "const_tbl_NewContractNo" to find the
next Contract No
' in the sequence; retreive it, increment it and write out the new
next contract no.
' If the function receives a 0 or a Null from the calling routine, it will
return the
' stored Contract No.
' If it receives a valid Contract No from the calling routine, it will
incement the number and
' store the next incremented number in the Table ready for the next use.
'*****************************************************************=**********************
On Error GoTo Err_GetNewContractNo
Dim dbs As Database, rs88 As Recordset, a As Long
Set dbs = CurrentDb
Set rs86 = dbs.OpenRecordset("const_tbl_NewContractNo", dbOpenDynaset)
' Get last Contract Number from "const_tbl_NewContractNo", increment it and
return.
rs86.MoveLast
If a = 0 Or a = Null Then
util_GetNewContractNo = rs86("ContractNo") ' return the Contract
No stored in the Table
ElseIf a = rs86("ContractNo") Then
rs86.MoveLast: rs86.Edit
rs86("ContractNo") = a + 1 ' Save incremented last Contract No
in "NewContractNo"
rs86.Update
util_GetNewContractNo = rs86("ContractNo") ' return the Contract
No stored in the Table
Else
MsgBox "Error you don't have the correct Contract Number",
vbOKOnly, "ERROR"
util_GetNewContractNo = 0 ' return 0 to
signify the error
End If
Exit_GetNewContractNo:
rs86.Close: dbs.Close
Exit Function
Err_GetNewContractNo:
Select Case Err
Case 0
Case Else
MsgBox Err.Description
Resume Exit_GetNewContractNo
End Select
End Function
Thanks for any pointers to get me in the right direction.
RayC