Reputation: 83
I am currently trying to create a number that increases per entry and group in my table via a form.
The form is rather simple it utilizes a ComboBox
to select the group from a different table. The generated number should start at 1 and increase for every new entry separately for each selected group.
Code:
My code attempts to create the number BeforeUpdate
by searching for the DMax()
of the variable for the group selected via ComboBox
. Unfortunately, in this current state, the code does not increment the variable called Nummer
but it does not throw an Error either.
Private Sub Nummer_BeforeUpdate(Cancel As Integer)
Nummer = Nz(DMax("[Nummer]", "Bau-Tagesbericht", "[Baustelle] = Kombinationsfeld354.Value")) + 1
End Sub
Variables:
Group: Baustelle
Variable that should be incremented: Nummer
Name of the Comobox
: Kombinationsfeld354
I appreciate any kind of help, thank you!
Upvotes: 1
Views: 91
Reputation: 55816
You need to concatenate the variable - and set 0 (zero) for Null:
Nummer = Nz(DMax("[Nummer]", "Bau-Tagesbericht", "[Baustelle] = " & Kombinationsfeld354.Value & ""), 0) + 1
If text value, use single quotes:
Nummer = Nz(DMax("[Nummer]", "Bau-Tagesbericht", "[Baustelle] = '" & Kombinationsfeld354.Value & "'"), 0) + 1
Upvotes: 1