Maneesh Massey
Member
Hi,
I am using the code below for auto-generating a 6-digit ID number in a text box on a userform. The code goes into the button-click event of a button on the form. The only problem with the code is, sometimes the button has to be clicked twice to generate the ID number in the text box. I fail to understand why this is happening ? Does anyone else have the same experience ?
I am using the code below for auto-generating a 6-digit ID number in a text box on a userform. The code goes into the button-click event of a button on the form. The only problem with the code is, sometimes the button has to be clicked twice to generate the ID number in the text box. I fail to understand why this is happening ? Does anyone else have the same experience ?
Code:
Private Sub cmdGenerateID_Click()
Dim Low As Long
Dim High As Long
Dim r As Long
Low = 1
High = 999999
r = Int((High - Low + 1) * Rnd() + Low)
Me.Textbox1.Value = r
End Sub
Last edited: