FatherJack
Programmer
I am new to Access VBA having spent several years programming Excel VBA. I am trying to write a small module to create 8 char passwords. As a start I have created a table with 2 fields and 36 rows.field 1 - key. field 2 chars a - z and 0 - 9. I have a sql string to query the table for the character according to the id which matches a random number generated each time (extract below).
QUESTION: how do you get the result of the select query into a variable?
Sub sql_module()
Dim db As Database
Dim rs As Recordset
Dim mysql As QueryDef
Dim myrndnum As Integer
Dim a As Integer
Dim t As String
Set db = CurrentDb
Set mysql = db.CreateQueryDef(""
Set rs = db.OpenRecordset("select * from [data]", dbOpenDynaset)
For a = 1 To 8
Randomize
myrndnum = Int((36 * Rnd) + 1) ' Generate random value between 1 and 36.
mysql.SQL = "Select data.letter from data where data.id = '" & myrndnum & "';"
t = ##result of select query##
Next a
End Sub
QUESTION: how do you get the result of the select query into a variable?
Sub sql_module()
Dim db As Database
Dim rs As Recordset
Dim mysql As QueryDef
Dim myrndnum As Integer
Dim a As Integer
Dim t As String
Set db = CurrentDb
Set mysql = db.CreateQueryDef(""
Set rs = db.OpenRecordset("select * from [data]", dbOpenDynaset)
For a = 1 To 8
Randomize
myrndnum = Int((36 * Rnd) + 1) ' Generate random value between 1 and 36.
mysql.SQL = "Select data.letter from data where data.id = '" & myrndnum & "';"
t = ##result of select query##
Next a
End Sub