remcop1989
Gebruiker
- Lid geworden
- 29 mrt 2012
- Berichten
- 492
Ik heb nu het probleem dat hij niet 1 optelt bij het huidige (hoogste) offertenummer in tabel "offertes"
Ik gebruik deze code in een module:
In het veld "Offertenummer" van het formulier "Nieuwe offerte" gebruik ik als standaardwaarde deze formule:
Ik gebruik deze code in een module:
Code:
Option Compare Database
Function NieuwVolgNummer(Veld As String, Tabel As String) As String
Dim strVolgNummer As String
Dim strNieuwVolgNummer As String
Dim strSQL As String, sInit As String
Dim tmpNummer
Dim tmp
'------------------------------------------------------------------------------------------------
' Huidige volgnummer uit tabel lezen die als parameter is meegegeven.
'------------------------------------------------------------------------------------------------
On Error Resume Next
sInit = DLookup("Initialen", "Gebruikers", "GebruikerID=" & UserID)
If sInit & "" = "" Then sInit = "XX"
On Error GoTo 0
strSQL = "SELECT TOP 1 [" & Veld & "] FROM Offertes " _
& "GROUP BY [" & Veld & "], Left([" & Veld & "],4), Val(Right([" & Veld & "],4)) " _
& "HAVING (CInt(Left([" & Veld & "], 4)) = " & Year(Date) & ") " _
& "ORDER BY Left([" & Veld & "],4) DESC , Val(Right([" & Veld & "],4)) DESC;"
With CurrentDb.OpenRecordset(strSQL)
On Error Resume Next
If .RecordCount > 0 And Nz(.Fields(0).Value, 0) <> 0 Then
strVolgNummer = .Fields(0).Value
Else
strVolgNummer = Format(0, "0000")
End If
End With
'------------------------------------------------------------------------------------------------
' Kijken of er een koppelteken in het volgnummer zit; vervolgens nieuw nummer maken.
'------------------------------------------------------------------------------------------------
If InStr(strVolgNummer, "-") > 0 Then
tmpNummer = Split(strVolgNummer, "-")
If CInt(Left(tmpNummer(UBound(tmpNummer)), 4)) = Year(Date) Then
strNieuwVolgNummer = _
CInt(Left(tmpNummer(UBound(tmpNummer)), 4)) & _
sInit & _
Right("0000" & CInt(Right(tmpNummer(UBound(tmpNummer)), 4)) + 1, 4)
Else
strNieuwVolgNummer = Year(Date) & sInit & CStr("0001")
End If
Else
strNieuwVolgNummer = Year(Date) & sInit & CStr("0001")
End If
'------------------------------------------------------------------------------------------------
' Nieuw nummer toekennen aan de functie.
'------------------------------------------------------------------------------------------------
NieuwVolgNummer = strNieuwVolgNummer
End Function
In het veld "Offertenummer" van het formulier "Nieuwe offerte" gebruik ik als standaardwaarde deze formule:
Code:
=NieuwVolgNummer("Offertenummer";"Offertes")