There are some solutions to the predicament I have now but non ive found so far are sufficient to how I want to apply it. I am creating an application that should have the unique random NUMERIC string concatenated into a Reference number. Here is one of the solutions I found:
Sub test()
Dim s As String * 8 'fixed length string with 8 characters
Dim n As Integer
Dim ch As Integer 'the character
For n = 1 To Len(s) 'don't hardcode the length twice
Do
ch = Rnd() * 127 'This could be more efficient.
'48 is '0', 57 is '9', 65 is 'A', 90 is 'Z', 97 is 'a', 122 is 'z'.
Loop While ch < 48 Or ch > 57 And ch < 65 Or ch > 90 And ch < 97 Or ch > 122
Mid(s, n, 1) = Chr(ch) 'bit more efficient than concatenation
Next
Debug.Print s
End Sub
Unfortunately it just creates one string and it is an alphabetic one. Im having difficulty converting VB.net code to VBA and thus I need to get a MS Access VBA solution that creates a unique numeric string of 5 characters every time the procedure is run.
Aucun commentaire:
Enregistrer un commentaire