Access BooK
Before start posting on this forum you must Login. If you are a new user, kindly register first.

Join the forum, it's quick and easy

Access BooK
Before start posting on this forum you must Login. If you are a new user, kindly register first.
Access BooK
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How to generate random string in MS Access VBA

2 posters

Go down

How to generate random string in MS Access VBA Empty How to generate random string in MS Access VBA

Post by Mani786 Wed Sep 14, 2016 10:11 pm

How to generate random string in MS Access ?

This is one way, will work in Access VBA  it will generate a string with letters Upper,Lower case and numbers. Add a command button in your form and add this code to Event Procedure:
Code:
   
    Dim RndmStr As String * 8
    Dim n As Integer
    Dim ch As Integer
    For n = 1 To Len(RndmStr)
        Do
            ch = Rnd() * 127
            
        Loop While ch < 48 Or ch > 57 And ch < 65 Or ch > 90 'And ch < 97 Or ch > 122
        Mid(RndmStr, n, 1) = Chr(ch)
    Next

    MsgBox "Random string is = " & RndmStr


Last edited by Mani786 on Wed Sep 14, 2016 10:25 pm; edited 3 times in total

Mani786
New member
New member

Posts : 94
Points : 172
Join date : 2013-12-14

Admin likes this post

Back to top Go down

How to generate random string in MS Access VBA Empty Re: How to generate random string in MS Access VBA

Post by Mani786 Wed Sep 14, 2016 10:16 pm

Try this function:
Code:
Public Function RndString() As String
   Dim Rndmstr As String, i As Integer, n As String
 
   Randomize (Int((122 - 48 + 1) * Rnd + 48))
 
   For i = 1 To 10
       n = Int((122 - 48 + 1) * Rnd + 48)
       Rndmstr = Rndmstr + Chr(n)
   Next i
   RndString = Rndmstr
End Function

Add a command button in your form and add this code to Event Procedure.
Code:
MsgBox RndString

Mani786
New member
New member

Posts : 94
Points : 172
Join date : 2013-12-14

Back to top Go down

How to generate random string in MS Access VBA Empty Re: How to generate random string in MS Access VBA

Post by wasif Sat Sep 24, 2016 8:53 pm

Thanks for this usefull post.....

wasif
New member
New member

Posts : 23
Points : 39
Join date : 2014-01-18

Back to top Go down

How to generate random string in MS Access VBA Empty Re: How to generate random string in MS Access VBA

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum