Get random number to be 10 digits long

Ok, now that I can get the random number to be generated, how do I get it to return 10-digit numbers only?
Public Function RandAccount() As Double
        RandAccount = Int((10000 * Rnd) + 1)
       
End Function
Private Sub Test()
Dim i As Integer
    For i = 1 To 50
    Call RandAccount
    Debug.Print RandAccount
    Next i
End Sub

Open in new window

Sandra SmithRetiredAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
oops:

Debug.Print Format(Int(CDec((10000000000# * Rnd) + 1)), "0000000000")
                   ^^^^^^^

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:

Public Function RandAccount() As Double
        Debug.Print Int(CDec((10000000000# * Rnd) + 1))
       
End Function

mx
0
 
Sandra SmithRetiredAuthor Commented:
Gives me 9 digits as well as 10.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Sandra SmithRetiredAuthor Commented:
Thanks, works.  
0
 
Sandra SmithRetiredAuthor Commented:
Even though it generates 0 in the first digit slot, this is OK as the numbers are translated back into text for various purposes and a leading 0 is not a problem.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
ok ... thx.mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.