VB6- Enterprise Edition Database=MS Access 2003
I have coded the following, it works however I have a problem in this senerio. : txtHomeName and txtVisitorName are Control arrays. Anywhere from 1 to 16 can be "loaded". If I have 16, the Insert works but less than 16, the Insert errors with a Syntax Error.
Question: How can I code the insert statement if there is a variable number iniput fields?
I have coded the following, it works however I have a problem in this senerio. : txtHomeName and txtVisitorName are Control arrays. Anywhere from 1 to 16 can be "loaded". If I have 16, the Insert works but less than 16, the Insert errors with a Syntax Error.
Question: How can I code the insert statement if there is a variable number iniput fields?
Code:
SQL = "Insert into AllTeams (WeekNumber, HTeam1, VTeam1, HTeam2, VTeam2, HTeam3, VTeam3, "
SQL = SQL & "HTeam4, VTeam4,HTeam5, VTeam5,HTeam6, VTeam6,HTeam7, VTeam7,HTeam8, VTeam8, "
SQL = SQL & "HTeam9, VTeam9,HTeam10, VTeam10,HTeam11, VTeam11,HTeam12, VTeam12,HTeam13, VTeam13, "
SQL = SQL & "HTeam14, VTeam14,HTeam15, VTeam15, HTeam16, VTeam16) values("
SQL = SQL & Val(txtWeekNumber.Text) & ", "
SQL = SQL & "'" & txtHomeName(0).Text & "', "
SQL = SQL & "'" & txtVisitorName(0).Text & "', "
SQL = SQL & "'" & txtHomeName(1).Text & "', "
SQL = SQL & "'" & txtVisitorName(1).Text & "', "
SQL = SQL & "'" & txtHomeName(2).Text & "', "
SQL = SQL & "'" & txtVisitorName(2).Text & "', "
SQL = SQL & "'" & txtHomeName(3).Text & "', "
SQL = SQL & "'" & txtVisitorName(3).Text & "', "
SQL = SQL & "'" & txtHomeName(4).Text & "', "
SQL = SQL & "'" & txtVisitorName(4).Text & "', "
SQL = SQL & "'" & txtHomeName(5).Text & "', "
SQL = SQL & "'" & txtVisitorName(5).Text & "', "
SQL = SQL & "'" & txtHomeName(6).Text & "', "
SQL = SQL & "'" & txtVisitorName(6).Text & "', "
SQL = SQL & "'" & txtHomeName(7).Text & "', "
SQL = SQL & "'" & txtVisitorName(7).Text & "', "
SQL = SQL & "'" & txtHomeName(8).Text & "', "
SQL = SQL & "'" & txtVisitorName(8).Text & "', "
SQL = SQL & "'" & txtHomeName(9).Text & "', "
SQL = SQL & "'" & txtVisitorName(9).Text & "', "
SQL = SQL & "'" & txtHomeName(10).Text & "', "
SQL = SQL & "'" & txtVisitorName(10).Text & "', "
SQL = SQL & "'" & txtHomeName(11).Text & "', "
SQL = SQL & "'" & txtVisitorName(11).Text & "', "
SQL = SQL & "'" & txtHomeName(12).Text & "', "
SQL = SQL & "'" & txtVisitorName(12).Text & "', "
SQL = SQL & "'" & txtHomeName(13).Text & "', "
SQL = SQL & "'" & txtVisitorName(13).Text & "', "
SQL = SQL & "'" & txtHomeName(14).Text & "', "
SQL = SQL & "'" & txtVisitorName(14).Text & "', "
SQL = SQL & "'" & txtHomeName(15).Text & "', "
SQL = SQL & "'" & txtVisitorName(15).Text & "'); "
EndInsert:
If Err.Number = 340 Or Err.Number = 0 Then
pconSports.Execute SQL, intRecordsAffected
Else
GoTo ErrHandler
End If