?
Solved

FlexGrid error (VB6/SQL2K)

Posted on 2005-05-13
6
Medium Priority
?
2,876 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:Mike Miller
  • 2
  • 2
  • 2
6 Comments
 

Author Comment

by:Mike Miller
ID: 13996907
sorry about the title....FlexGrid not data grid
0
 
LVL 6

Expert Comment

by:PePi
ID: 13997208
it would greatly help if you could tell us where exactly the error occurs
0
 

Author Comment

by:Mike Miller
ID: 13997266
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:PePi
ID: 13997647
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
 
LVL 12

Accepted Solution

by:
Preece earned 2000 total points
ID: 13999442
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
 
LVL 12

Expert Comment

by:Preece
ID: 13999469
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question