How to generate random string in MS Access VBA
2 posters
Page 1 of 1
How to generate random string in MS Access VBA
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:
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
- Posts : 94
Points : 172
Join date : 2013-12-14
Admin likes this post
Re: How to generate random string in MS Access VBA
Try this function:
Add a command button in your form and add this code to Event Procedure.
- 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
- Posts : 94
Points : 172
Join date : 2013-12-14
Re: How to generate random string in MS Access VBA
Thanks for this usefull post.....
wasif- New member
- Posts : 23
Points : 39
Join date : 2014-01-18
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum