Thank you for the project. It really helped to understand why this crash occurs. In two words, the problem occurs as you refer a combo box that does not exist.
See, you define the columns in which the problem occurs using the following code in the PopulateGridLayout sub:
With .AddCol(sKey:=vGridFields(iGrd, i, 3), sHeader:=vGridFields(iGrd, i, 1), lWidth:=vGridFields(iGrd, i, 2), eHeaderAlignH:=vGridFields(iGrd, i, 10))
.eType = igCellCombo
.sCtrlKey = vGridFields(iGrd, i, 3)
.eAlignH = vGridFields(iGrd, i, 10)
End With
You expect that the combos you are going to use in the columns are created in the g_pSetComboItemValue sub:
Public Sub g_pSetComboItemValue(ByVal iGrd As Integer, ByVal sSQL As String, ByVal vTextField As Variant, ByVal vValueField As Variant)
On Error Resume Next
Dim rsFillCombo As ADODB.Recordset
Dim cboGrid As ComboObject ' An iGrid combo list
Set rsFillCombo = New ADODB.Recordset
If rsFillCombo.State = 1 Then rsFillCombo.Close
rsFillCombo.Open sSQL, gConnectDB, adOpenForwardOnly, adLockReadOnly
If Not rsFillCombo.EOF Then
With iGridName(iGrd)
.BeginUpdate
Set cboGrid = .Combos.Add(vValueField)
cboGrid.FillFromRS rsFillCombo, vTextField, vValueField
cboGrid.AutoAdjustWidth
.EndUpdate
End With
End If
Set rsFillCombo = Nothing
End Sub
However, if the recordset does not contain any records, the combo object is not created too!
To fix the problem, we need to create the combo object in any case - regardless of the number of records in the recordset. I rewrote your g_pSetComboItemValue sub accordingly, and in my version of your project it looks like this:
Public Sub g_pSetComboItemValue(ByVal iGrd As Integer, ByVal sSQL As String, ByVal vTextField As Variant, ByVal vValueField As Variant)
On Error Resume Next
Dim rsFillCombo As ADODB.Recordset
Dim cboGrid As ComboObject ' An iGrid combo list
Set rsFillCombo = New ADODB.Recordset
If rsFillCombo.State = 1 Then rsFillCombo.Close
rsFillCombo.Open sSQL, gConnectDB, adOpenForwardOnly, adLockReadOnly
Set cboGrid = iGridName(iGrd).Combos.Add(vValueField)
If Not rsFillCombo.EOF Then
cboGrid.FillFromRS rsFillCombo, vTextField, vValueField
cboGrid.AutoAdjustWidth
End If
Set rsFillCombo = Nothing
End Sub
Note that we do not need to call iGrid's BeginUpdate/EndUpdate when we create a combo list and populate it because there are no objects in the iGrid viewport that must be redrawn.