Ahmed
  • Ahmed
  • Newbie Topic Starter
2019-08-22T11:13:14Z
I'm just trying to add iGrid control to a from in runtime declaring withevents. I know I can add it like this:

Dim iGridData As Control
Set iGridData = UserForm1.Controls.Add("iGrid700_10Tec.iGrid", sPageName(0), True)


But when I declare it withevents I come across an error:

Public WithEvents iGridDataX As Control
Set iGridDataX = UserForm1.Controls.Add("iGrid700_10Tec.iGrid", sPageName(0), True)


UserPostedImage 
Igor/10Tec
2019-08-22T16:13:22Z
We couldn't see your screenshot as it is a link to your local file. However, if you write that the WithEvents keyword causes the error 459 or something like that, then the problem is definitely not in iGrid ActiveX. This is a limitation of VBA or something like that. Perhaps, you should ask this question on specialized VBA forums or related Microsoft resources.
Ahmed
  • Ahmed
  • Newbie Topic Starter
2019-08-22T22:06:42Z
Thanks for the reply. I corrected the screen-shot.
The thing is that it's OK with other controls like Multipage:

Public WithEvents MultiPageData As MultiPage
Set MultiPageData = UserForm1.Controls.Add("Forms.MultiPage.1", sMultiPageName, True)

Private Sub MultiPageData_Change()
    Me.Label1.Caption = MultiPageData.SelectedItem.Name
End Sub
Ahmed
  • Ahmed
  • Newbie Topic Starter
2019-08-27T03:07:16Z
Any answer to this please?
Ahmed
  • Ahmed
  • Newbie Topic Starter
2019-08-29T03:56:44Z
I tried this too, but no success:

Dim WithEvents iGridDataX As igrid

Private Sub UserForm_Initialize()

    Set iGridDataX = iGrid1.Object
    
End Sub

"iGrid1" control has been created in design mode.

I receive Run-time error 438: "Object doesn't support this property or method"
[img]https://ibb.co/g9Mh6PM[/img]
Imran
2019-08-29T20:30:24Z
Ahmed,
I do something similar, I have a class module that has a grid object in it

Dim WithEvents moGridTalentArea As clsBasicGrid
Private Sub Form_Load()

    Set moGridTalentArea = New clsBasicGrid
    Set moGridTalentArea.moGrid = iGridTalentArea.Object

End Sub


iGridTalentArea is a 10Tec Grid object on the form design.
Ahmed
  • Ahmed
  • Newbie Topic Starter
2019-08-29T23:14:15Z
Thanks Imran for the reply. I'm not very good at VB.
Just wondering what clsBasicGrid is? Have you created it or it's just an iGrid? Could you please explain more?

And also I don't get moGrid...

Imran
2019-08-30T13:48:14Z
clsBasicGrid is a MS Access VBA Class Module, here is the code for it:

Option Compare Database
Option Explicit

Public Event AfterSelectionChange(ByVal sKey As String)

Public WithEvents moGrid As iGrid

Private Sub moGrid_AfterSelectionChange( _
        ByVal bSelContentsChanged As Boolean)
   
    Dim lRow As Long
    Dim sRowKey As String
    
    With moGrid
        
        If .SelItems.count > 0 Then
            lRow = .SelItems.GetArray()(1).Row
            sRowKey = .RowKey(lRow)
            
            RaiseEvent AfterSelectionChange(sRowKey)
        
        End If

    End With
    
End Sub



Then my form has an iGrid on it called iGridTalentArea. These two subroutines are in the form, they link the iGrid to the Class Module and handle the event.


Option Compare Database
Option Explicit

Dim WithEvents moGridTalentArea As clsBasicGrid

Private Sub Form_Load()

    Set moGridTalentArea = New clsBasicGrid
    Set moGridTalentArea.moGrid = iGridTalentArea.Object
    
End Sub

Private Sub moGridTalentArea_AfterSelectionChange(ByVal sKey As String)
    MsgBox (sKey)
End Sub
Ahmed
  • Ahmed
  • Newbie Topic Starter
2019-08-31T02:29:00Z
The thing is that the code works fine in MS Access but in Excel it gives an error (438: Object doesn't support this property or method):

Set iGridData.xiGrid = iGrid1.Object


This is the class (clsMyClass) I've defined:
Option Explicit

Public Event Click(ByVal sKey As String)
Public WithEvents xiGrid As iGrid700_10Tec.igrid

Private Sub xiGrid_Click(ByVal lRowIfAny As Long, ByVal lColIfAny As Long)

MsgBox "Done!"

End Sub

And this the code for the Form containing iGrid1 control:
Option Explicit
Public WithEvents iGridData As clsMyClass

Private Sub UserForm_Initialize()

    Me.iGrid1.ColCount = 2
    Me.iGrid1.AddRow
    Me.iGrid1.AddRow

    Set iGridData = New clsMyClass
    Set iGridData.xiGrid = iGrid1.Object

End Sub


You can have a look at the iGrid_WithEvents.xlsm  file if you'd like.
Imran
2019-09-05T14:19:10Z
Ahmed, Unfortunately, I don't use iGrid in Excel.