1
ห้อง MS Access / : สุ่มคำศัพท์15คำเพื่อฟังการอ่านออกเสียง10คนเนื้อหาไม่ซ้ำสั่งพิมพ์ทีเดียวได้10หน้า
« เมื่อ: 25 ก.ค. 65 , 10:54:05 »
น่าจะคล้ายๆ อันนี้ เผื่อมีคนถนัดแวะมาตอบครับ
It needs to be a function not a Sub. So it should be:
Public Function RandNo() AS Integer
Dim iRNumber As Integer
Randomize
RandNo = Int((200 - 100 + 1) * Rnd + 100)
End Function
This will return the random number you want.
To add this to a table you could use code like:
Dim SQL As String
Dim i as Integer
For i = 1 to 5
strSQL = "INSERT INTO table (Field1, Field2, Filed3) " & _
"VALUES(" & RandNo() & ", " & RandNo() & ", " & RandNo() & ");"
CurrentDB.Execute strSQL, dbFailOnError
Next i
If you need further clarification on this feel free to ask.
It needs to be a function not a Sub. So it should be:
Public Function RandNo() AS Integer
Dim iRNumber As Integer
Randomize
RandNo = Int((200 - 100 + 1) * Rnd + 100)
End Function
This will return the random number you want.
To add this to a table you could use code like:
Dim SQL As String
Dim i as Integer
For i = 1 to 5
strSQL = "INSERT INTO table (Field1, Field2, Filed3) " & _
"VALUES(" & RandNo() & ", " & RandNo() & ", " & RandNo() & ");"
CurrentDB.Execute strSQL, dbFailOnError
Next i
If you need further clarification on this feel free to ask.