Public Function GenerateRandomRecords(ByVal iNumber) As Boolean
Dim sSql As String
Dim sZone As String
On Error Resume Next
'Assume the worst
GenerateRandomRecords = False
sZone = "West"
If iNumber <= 0 Then
MsgBox "Invalid number of records to generate specified"
Else
'Build SQL
sSql = "INSERT INTO tblAudits (Building, Location, Floor, LocationType, [Zone], DateSelected) "
sSql = sSql & "SELECT TOP " & iNumber & " Building, Location, Floor, LocationType, [Zone], Now() "
sSql = sSql & "FROM tblLocations "
sSql = sSql & "WHERE tblLocations.Zone=" & sZone & " "
sSql = sSql & "ORDER BY RND(ID);"
Err.Clear
CurrentDb.Execute sSql, dbFailOnError
If Err.Number = 0 Then
GenerateRandomRecords = True
Else
MsgBox Err.Description
End If
End If
End Function
|