FlexGrid error (VB6/SQL2K)

When attempting to open a form with a FlexGrid on it I get this error...

Run-time error 30010 Invalid column value

This only occurs on the user machines, not my development machine. Here's the code:

Private Const MARGIN_SIZE = 1000      ' in Twips
' variables for column dragging
Private m_bDragOK As Boolean
Private m_iDragCol As Integer
Private xdn As Integer, ydn As Integer

Private Sub Form_Load()
    Dim I As Integer

    datPrimaryRS.Visible = False

    With MSHFlexGrid1

        .Redraw = False
        ' set grid's column widths
        .ColWidth(0) = 2000
        .ColWidth(1) = 2000
        .ColWidth(2) = 2000
        .ColWidth(3) = 2000
        ' set grid's column merging and sorting
        For I = 0 To .Cols - 1
            .MergeCol(I) = True
        Next I

        .Sort = flexSortGenericAscending

        ' set grid's style
        .AllowBigSelection = True
        .FillStyle = flexFillRepeat

        ' make header bold
        .Row = 0
        .Col = 0
        .RowSel = .FixedRows - 1
        .ColSel = .Cols - 1
        .CellFontBold = True

        ' grey every other column
        For I = .FixedCols To .Cols() - 1 Step 2
            .Col = I
            .Row = .FixedRows
            .RowSel = .Rows - 1
            .CellBackColor = &HC0C0C0   ' light grey
        Next I

        .AllowBigSelection = False
        .FillStyle = flexFillSingle
        .Redraw = True

    End With
  Dim db2 As Connection
  Dim strSQL2 As String
  Set db2 = New Connection
  db2.CursorLocation = adUseClient
  db2.Open "PROVIDER=MSDASQL;driver={SQL Server};server=USSRM-FP04;uid=;pwd=;database=PhysicalInventory;"
  Set adoPrimaryRS2 = New Recordset
  strSQL2 = "SELECT SUM(CAST(cast(imMTownStock.Cost as float) * cast(imMTownStock.Quantity as float) - cast(Main.Cost as float) * CAST(Main.Quantity as float) AS DECIMAL(20, 2))) AS NetTotal FROM Main LEFT JOIN imMTownStock ON ([Main].PART_NUMBER = [imMTownStock].PartNumber AND [Main].Quantity <> [imMTownStock].Quantity)"

Debug.Print strSQL2

adoPrimaryRS2.Open strSQL2, db2, adOpenStatic, adLockOptimistic
lblTotal.Caption = adoPrimaryRS2(0)
End Sub



Private Sub imgPrint_Click()
Call MSFlexGridPrint(MSHFlexGrid1)
End Sub

Private Sub MSHFlexGrid1_DragDrop(Source As Control, X As Single, Y As Single)
'-------------------------------------------------------------------------------------------
' code in grid's DragDrop, MouseDown, MouseMove, and MouseUp events enables column dragging
'-------------------------------------------------------------------------------------------

    If m_iDragCol = -1 Then Exit Sub    ' we weren't dragging
    If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub

    With MSHFlexGrid1
        .Redraw = False
        .ColPosition(m_iDragCol) = .MouseCol

        .FillStyle = flexFillRepeat
        .Col = 0
        .Row = .FixedRows
        .RowSel = .Rows - 1
        .ColSel = .Cols - 1
        .CellBackColor = &HFFFFFF
        Dim iLoop As Integer
        For iLoop = .FixedCols To .Cols() - 1 Step 2
            .Col = iLoop
            .Row = .FixedRows
            .RowSel = .Rows - 1
            .CellBackColor = &HC0C0C0
        Next iLoop
        .FillStyle = flexFillSingle

        DoSort
        .Redraw = True
    End With

End Sub

Private Sub MSHFlexGrid1_MouseDown(Button As Integer, shift As Integer, X As Single, Y As Single)
'-------------------------------------------------------------------------------------------
' code in grid's DragDrop, MouseDown, MouseMove, and MouseUp events enables column dragging
'-------------------------------------------------------------------------------------------

    If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub

    xdn = X
    ydn = Y
    m_iDragCol = -1     ' clear drag flag
    m_bDragOK = True

End Sub

Private Sub MSHFlexGrid1_MouseMove(Button As Integer, shift As Integer, X As Single, Y As Single)
'-------------------------------------------------------------------------------------------
' code in grid's DragDrop, MouseDown, MouseMove, and MouseUp events enables column dragging
'-------------------------------------------------------------------------------------------

    ' test to see if we should start drag
    If Not m_bDragOK Then Exit Sub
    If Button <> 1 Then Exit Sub                        ' wrong button
    If m_iDragCol <> -1 Then Exit Sub                   ' already dragging
    If Abs(xdn - X) + Abs(ydn - Y) < 50 Then Exit Sub   ' didn't move enough yet
    If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub         ' must drag header

    ' if got to here then start the drag
    m_iDragCol = MSHFlexGrid1.MouseCol
    MSHFlexGrid1.Drag vbBeginDrag

End Sub

Private Sub MSHFlexGrid1_MouseUp(Button As Integer, shift As Integer, X As Single, Y As Single)
'-------------------------------------------------------------------------------------------
' code in grid's DragDrop, MouseDown, MouseMove, and MouseUp events enables column dragging
'-------------------------------------------------------------------------------------------

    m_bDragOK = False

End Sub

Sub DoSort()

    With MSHFlexGrid1
        .Redraw = False
        .Col = 0
        .Row = 1
        .RowSel = .Rows - 1
        .Sort = flexSortGenericAscending
        .Redraw = True
    End With

End Sub

Private Sub Form_Resize()

    Dim sngButtonTop As Single
    Dim sngScaleWidth As Single
    Dim sngScaleHeight As Single

           
           
    On Error GoTo Form_Resize_Error
    With Me
        sngScaleWidth = .ScaleWidth
        sngScaleHeight = .ScaleHeight

        ' move Close button to the lower right corner
        With .cmdClose
                sngButtonTop = sngScaleHeight - (.Height + MARGIN_SIZE)
                .Move sngScaleWidth - (.Width + MARGIN_SIZE), sngButtonTop
        End With
       

       
        .MSHFlexGrid1.Move MARGIN_SIZE, _
            MARGIN_SIZE, _
            sngScaleWidth - (2 * MARGIN_SIZE), _
            sngButtonTop - (2 * MARGIN_SIZE)

    End With
    Exit Sub

Form_Resize_Error:
    ' avoid error on negative values
    Resume Next



End Sub

Private Sub cmdClose_Click()

    Unload Me

End Sub

Public Sub MSFlexGridPrint(gridQuery As Control)
   ' *** Print MSFlexGrid

   Dim I          As Integer
   Dim J          As Integer
   Dim PTab       As Integer

   For I = 0 To gridQuery.Rows - 1
      PTab = 20 'Set the first tab value
      'This checks to see if a page break is needed

      If Printer.CurrentY + Printer.TextHeight(gridQuery.Text) > Printer.ScaleHeight - 600 Then
         Printer.NewPage
      End If

      gridQuery.Row = I 'Set the active row

      For J = 0 To gridQuery.Cols - 1
         gridQuery.Col = J 'Set the current column
         
         'Send the field to the print line and add the tab.
         'Notice the semicolon at the end of the line.

         Printer.Print Trim$(gridQuery.Text); Tab(PTab);

         PTab = PTab + 20 'Increment the tab value
      Next

      'After each column has printed to the print line

      'a Printer.Print statement without a semicolon will
      'will send the line to the printer and start a new
      'one.
      Printer.Print
     
 Next
Printer.EndDoc
End Sub



What should I be looking for? TIA
Mike MillerSoftware EngineerAsked:
Who is Participating?
 
PreeceCommented:
I would suggest some more robust error handling.  This:

Exit Sub

Form_Resize_Error:
    ' avoid error on negative values
    Resume Next

isn't doing much good, other than continuing execution.  Try something like:

Exit Sub

Form_Resize_Error:
    Select Case Err.Number
    Case ???? ' for negative values
        Resume Next
    Case Else
        msgbox "An error occurred in Form1.Form_Resize.  Err Number:  " & Err.Number & ".  Err Description:  " & Err.Description
    End Select
End Sub

I would put error handling code in each procedure, until you figure out the problem...
0
 
Mike MillerSoftware EngineerAuthor Commented:
sorry about the title....FlexGrid not data grid
0
 
PePiCommented:
it would greatly help if you could tell us where exactly the error occurs
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Mike MillerSoftware EngineerAuthor Commented:
thats the thing...i can't tell. when i run it on my machine, it works fine. when i step through...its great.
on the user machine when i click the button that loads the form in question, it gives the error and then
exits the app. i only registered MSHFLEXGD.OCX. did i need to register something else?

0
 
PePiCommented:
my guess would be that the MSHFlexGrid.ocx was not properly registered. How do you deploy your application? Do you just copy the EXE and register all dlls and ocxs manually? It may be that MSHFlexGrid.ocx has related dlls that need to be registered too.
0
 
PreeceCommented:
Be sure to change the component.module name for each procedure you add error handling to.  

Also, you could number your code lines and add to the error msg the line number (Erl):

msgbox "An error occurred in Form1.Form_Resize at line:  " & Erl & ".  Err Number:  " & Err.Number & ".  Err Description:  " & Err.Description

Hope this helps!
Preece
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.