Public Function GetNSequence() As String
'This function is used to provide the next N packet number to be used
gstrFunctionName = "GetNSequence"
gstrModuleName = "basGeneralFunctions"
On Error GoTo ProcError
Dim dbTSPE As Database
Dim rsSettings As Recordset
Dim strPacketNo As String
Dim intStrLength As Integer
Dim varNumSequence As Variant
Dim strLastPacketNo As String
Set dbTSPE = CurrentDb()
Set rsSettings = dbTSPE.OpenRecordset("tspeSettings", dbopendynaset)
With rsSettings
If .RecordCount = 0 Then
MsgBox "System settings have not been defined! Please contact technical support.", vbCritical + vbOKOnly, "Packet Entry"
Exit Function
Else
.MoveFirst
.Edit
If IsNull(!nsequence) = True Then
'Starting up program for the first time?
'use N0 as first packet no.
!nsequence = "N0"
strPacketNo = "N0"
Else
'extract the number from a string and increase by one to get the next number in sequence
strLastPacketNo = !nsequence
intStrLength = Len(strLastPacketNo)
varNumSequence = Right(strLastPacketNo, intStrLength - 1)
varNumSequence = varNumSequence + 1
strPacketNo = "N" & varNumSequence
!nsequence = strPacketNo
End If
.Update
.Close
End If
End With
Set rsSettings = Nothing
Set dbTSPE = Nothing
GetNSequence = strPacketNo
ProcExit:
Exit Function
ProcError:
Dim intError As Integer
intError = ErrorHandler(gstrFunctionName, gstrModuleName)
GoTo ProcExit
End Function
Evo funkcije, u ovom slucaju stavlja se N pre broja. Ti ces morati da citas string s leve strane, dok ne naidjes na nulu. Ako ce program koristiti 2 ili vise usera, kada funkcija vrati rezultat nije lose da proveris da li se taj string vec ne nalazi u bazi, i ako vec jeste tu onda pozovi funkciju opet.
All beer is good. Some beer is better.