Shape command for MSHFlexGrid
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Shape command for MSHFlexGrid

  1. #1
    Join Date
    Jul 2008
    Posts
    29

    Question Shape command for MSHFlexGrid

    Hello,

    I am using MSHFlexGrid and following is the code:

    Dim strCn As String

    strCn = "connection string"

    Dim strSh As String

    strSh = "SHAPE {SELECT * FROM `Customer`} AS Customers APPEND ({SELECT * FROM `Order`} AS Orders RELATE Cust_ID TO Cust_ID) AS Orders"

    With Adodc1
    .ConnectionString = strCn
    .RecordSource = strSh
    End With

    Set MSHFlexGrid1.DataSource = Adodc1

    But when I run code it gives me following error:

    Invalid SQL Statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' or 'UPDATE'.

    What can be done????

    Regards,

    Prachi

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,860

    Re: Shape command for MSHFlexGrid

    "connection string" is not a valid connection string
    I do not use the data control nor do I use shape so I am not real sure about your select.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    Re: Shape command for MSHFlexGrid

    Here's a sample that uses OLE (which is old)

    Code:
    Private Sub Command1_Click()
        Dim cnLvConnection As ADODB.Connection
        Set cnLvConnection = New ADODB.Connection
        Dim rsLvRecordset As ADODB.Recordset
        Set rsLvRecordset = New ADODB.Recordset
        With cnLvConnection
            .Provider = "MSDataShape.1"
            .ConnectionString = "Data Source=" & App.Path & "\db1.mdb;" _
                              & "Data Provider=Microsoft.Jet.OLEDB.4.0;"
            .Open
            With rsLvRecordset
                .CursorLocation = adUseClient
                .CursorType = adOpenStatic
                .LockType = adLockReadOnly
            End With
            Set rsLvRecordset = .Execute("SHAPE {SELECT c.CustomerName As Customer, c.CustomerID FROM Customers c ORDER BY c.CustomerName} As Customers" _
                                       & " APPEND ((SHAPE {SELECT oh.OrderNumber As [Order No], oh.CustomerID, oh.OrderHeaderID FROM OrderHeaders oh ORDER BY oh.OrderNumber} As OrderHeaders" _
                                       & "          APPEND ({SELECT od.OrderLine As [Line], od.OrderLineDescription As [Description], od.OrderLineQuantity As Quantity, od.OrderHeaderID FROM OrderDetails od ORDER BY od.OrderLine} As OrderDetails" _
                                       & "          RELATE OrderHeaderID TO OrderHeaderID))" _
                                       & " RELATE CustomerID TO CustomerID)")
        End With
        '   Setup Grid
        Set Me.MSHFlexGrid1.Recordset = rsLvRecordset
        Me.MSHFlexGrid1.ColWidth(1, 0) = 0 ' c.CustomerID
        Me.MSHFlexGrid1.ColWidth(1, 1) = 0 ' oh.CustomerID
        Me.MSHFlexGrid1.ColWidth(2, 1) = 0 ' oh.OrderHeaderID
        Me.MSHFlexGrid1.ColWidth(3, 2) = 0 ' od.OrderHeaderID
        '   Tidy up
        If Not rsLvRecordset Is Nothing Then
            If rsLvRecordset.State <> adStateClosed Then
                rsLvRecordset.Close
            End If
            Set rsLvRecordset = Nothing
        End If
        If Not cnLvConnection Is Nothing Then
            If cnLvConnection.State <> adStateClosed Then
                cnLvConnection.Close
            End If
            Set cnLvConnection = Nothing
        End If
    End Sub
    
    Private Sub Form_Load()
        Me.MSHFlexGrid1.FixedCols = 0
    End Sub
    
    '
    '  Edit the cell, without the update
    
    Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
       If KeyAscii = vbKeyReturn Then   'enter key
        'move to next cell.
            With MSHFlexGrid1
                If .Col + 1 <= .Cols - 1 Then
                    .Col = .Col + 1
                Else
                    If .Row + 1 <= .Rows - 1 Then
                        .Row = .Row + 1
                        .Col = 0
                    Else
                        .Row = 1
                        .Col = 0
                    End If
                End If
            End With
        ElseIf KeyAscii = vbKeyBack Then   'back space key
            With MSHFlexGrid1
                'back space out the entered characters
                If Len(.Text) Then
                    .Text = Left(.Text, Len(.Text) - 1)
                End If
            End With
        Else
            With MSHFlexGrid1
                .Text = .Text & Chr(KeyAscii)
            End With
        End If
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jul 2008
    Posts
    29

    Thumbs up Re: Shape command for MSHFlexGrid

    Thank you so much! it worked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center