Hello
I have this code in one of my form. When I try to run it I get an error message about "SQL expression is too complex" whenever I have more than 25 rows in my GroupAttendance listbox. The code below works fine when I have less than 25 items.
Is there a limit on how many rows you can attempt to INSERT in SQL?
Private Sub Command103_Click()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL1 As String, strSQL2 As String, strSQL3 As String
Dim ndx As Integer
Dim rowcount As Integer
'Store all clientid in groupattendance in a temporary table
strSQL1 = "INSERT INTO tblTemp ( clientid ) "
strSQL1 = strSQL1 & "SELECT dsdtcmas.clientid "
strSQL1 = strSQL1 & "FROM dsdtcmas "
strSQL1 = strSQL1 & "WHERE dsdtcmas.clientid In ("
'build the sql string by adding one clientid after another as it iterates down the listbox
For ndx = 0 To Me!GroupAttendance2.ListCount - 1
strSQL1 = strSQL1 & Chr(34) & Me!GroupAttendance2.ItemData(ndx) & Chr(34) & ", "
Next ndx
'remove last ", " and add closing parenthesis
strSQL1 = Left$(strSQL1, Len(strSQL1) - 2) & ")"
MsgBox strSQL1
DoCmd.RunSQL strSQL1
end sub
Thank you.
Chillay
I have this code in one of my form. When I try to run it I get an error message about "SQL expression is too complex" whenever I have more than 25 rows in my GroupAttendance listbox. The code below works fine when I have less than 25 items.
Is there a limit on how many rows you can attempt to INSERT in SQL?
Private Sub Command103_Click()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL1 As String, strSQL2 As String, strSQL3 As String
Dim ndx As Integer
Dim rowcount As Integer
'Store all clientid in groupattendance in a temporary table
strSQL1 = "INSERT INTO tblTemp ( clientid ) "
strSQL1 = strSQL1 & "SELECT dsdtcmas.clientid "
strSQL1 = strSQL1 & "FROM dsdtcmas "
strSQL1 = strSQL1 & "WHERE dsdtcmas.clientid In ("
'build the sql string by adding one clientid after another as it iterates down the listbox
For ndx = 0 To Me!GroupAttendance2.ListCount - 1
strSQL1 = strSQL1 & Chr(34) & Me!GroupAttendance2.ItemData(ndx) & Chr(34) & ", "
Next ndx
'remove last ", " and add closing parenthesis
strSQL1 = Left$(strSQL1, Len(strSQL1) - 2) & ")"
MsgBox strSQL1
DoCmd.RunSQL strSQL1
end sub
Thank you.
Chillay