I have a vba for generating a random number. This number is generated after opening the form, this is good, but it also needs to generate a code after a new record is made, how can this be done?
Private Sub Form_Open(Cancel As Integer)
Dim strPin As String
Dim i As Integer
strPin = "JobNr: "
'Set seed
Call Randomize
For i = 1 To 5
strPin = strPin & Int(10 * Rnd)
Next
Me.random_nr = strPin
End Sub
If that code is doing what you want, you can move it to a separate procedure in the form’s module.
Then change Form Open:
And call it again from the form’s After Insert event.