
? 3014 Can't open any more tables - Click header to sort by column fails
I have a DBgrid set up to sort by a column. But after ~20
click-header-sort column events, I get '3014 Can't open any more tables'.
Tried closing the old recordsets that were being replace but no effect.
TBH
Jeff
Private Sub cmdSort_Click()
On Error GoTo SortErr
Dim recRecordset1 As Recordset, recRecordset2 As Recordset
Dim SortStr As String
If data1.RecordsetType = vbRSTypeTable Then
Beep
MsgBox "You Cannot Sort a Table Recordset!", 48
Exit Sub
End If
Set recRecordset1 = data1.Recordset.Clone 'copy
the recordset
If Len(msSortCol) = 0 Then
SortStr = InputBox("Enter Sort Column:")
If Len(SortStr) = 0 Then Exit Sub
Else
SortStr = msSortCol
End If
Screen.MousePointer = vbHourglass
recRecordset1.Sort = SortStr
'establish the Sort
Set recRecordset2 = recRecordset1.OpenRecordset(recRecordset1.Type)
data1.Recordset.Close
Set data1.Recordset = recRecordset2
recRecordset1.Close
Screen.MousePointer = vbDefault
Exit Sub
SortErr:
Screen.MousePointer = vbDefault
MsgBox "Sort Error:" & Err & " " & Err.Description
End Sub
Private Sub grdDataGrid_HeadClick(ByVal ColIndex As Integer)
'let's sort on this column
If data1.RecordsetType = vbRSTypeTable Then Exit Sub
'check for the use of the ctrl key for descending sort
If mbCtrlKey Then
msSortCol = "[" & grdDataGrid.Columns(ColIndex).DataField & "] desc"
mbCtrlKey = 0 'reset it
Else
msSortCol = "[" & grdDataGrid.Columns(ColIndex).DataField & "]"
End If
cmdSort_Click
msSortCol = vbNullString 'reset it
End Sub