I'm trying to add 50,000 records to my Tournament_Result table in Microsoft Access but I have encountered this error: Run-time error '3075: Syntax error (missing operator) in query expression "1st", 'A', 1-Jan-15', '1')'.
Option Compare Database
Option Explicit
Sub arrayData()
Dim TournamentResult() As Variant
Dim DivisionEntered() As Variant
Dim DateOfTournament() As Variant
Dim num As Long, TournamentResultNo As Long, MembershipNo As Long, dbs As Database, InsertRecord As String
Dim num1 As Long 'we need to declare num1 as an Integer to create a loop
Dim TournamentResultDescription As String, DivisionEnteredDescription As String, DateOfTournamentDescription As String
Set dbs = CurrentDb()
TournamentResultNo = 0
MembershipNo = 0
TournamentResultNo = TournamentResultNo + 1
TournamentResult = Array("1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th")
DivisionEntered = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")
DateOfTournament = Array("1-Jan-15", "2-Feb-15", "3-Mar-15", "4-Apr-15", "5-May-15", "6-Jun-15", "7-July-15", "8-Aug-15", "9-Sep-15", "10-Oct-15", "11-Nov-15", "12-Dec-15")
MembershipNo = MembershipNo + 1
For num1 = 0 To 50000
num = Int((50000 - 0 + 1) * Rnd + 0)
TournamentResultDescription = TournamentResult(num)
DivisionEnteredDescription = DivisionEntered(num)
DateOfTournamentDescription = DateOfTournament(num)
InsertRecord = "insert into TOURNAMENT_RESULT(TournamentResultNo, TournamentResult, DivisionEntered, DateOfTournament, MembershipNo) values (" & "'" & TournamentResultNo & "'" & "," & "'" & TournamentResultDescription & "'" & "'" & "," & "'" & DivisionEnteredDescription & "'" & "," & "'" & DateOfTournamentDescription & "'" & "," & "'" & MembershipNo & "'" & ")"
dbs.Execute InsertRecord
Debug.Print TournamentResultNo; TournamentResultDescription; DivisionEnteredDescription; DateOfTournamentDescription; MembershipNo
Next
End Sub
EDIT: dbs.Execute InsertRecord
is highlighted as the problem