Requery GPF revisited 
Author Message
 Requery GPF revisited

I have a test project consisting of 3 forms.  
The first has 3 buttons and 1 ListBox.
The others have 1 ListBox.
All of the ListBoxes are displaying Collections of class
objects using very similar code.  The ListBox on the
opening form and one of the forms opened by a button on
the first form work.  The other produces a GPF when I
requery theListBox after populating the Collection.

I have not been able to find any reference to this problem,
has anyone else seen it?

Is the project fatally corrupted after the GPF?

' *********************************** Form1 Code

Private List As Collection

Private Sub Command0_Click()
    Form_Form2.edit
End Sub

Private Sub Command1_Click()
    Form_Form3.edit
End Sub

Private Sub Command2_Click()
    Dim thing As BillDef
    Dim key As String

    Set List = New Collection

    Set thing = New BillDef
    thing.Id = 1
    thing.Name = "Foo"
    thing.Amount = 10.23
    key = thing.Id
    List.Add thing, key

    Set thing = New BillDef
    thing.Id = 2
    thing.Name = "Bar"
    thing.Amount = 30.2
    key = thing.Id
    List.Add thing, key

    Me.List3.Requery
End Sub

Function source _
( _
    fld As Control, _
    Id As Variant, _
    row As Variant, _
    col As Variant, _
    code As Variant _
) As Variant
    Dim ReturnVal As Variant
    ReturnVal = Null

    Select Case code
        Case acLBInitialize                ' Initialize.
            If IsNull(billList) Then
                ReturnVal = False
            Else
                ReturnVal = True
            End If

        Case acLBOpen                        ' Open.
            ' Generate unique ID for control.
            ReturnVal = Timer

        Case acLBGetRowCount            ' Get number of
rows.
            If Not List Is Nothing Then
                ReturnVal = List.Count + 1
            Else
                ReturnVal = 1
            End If

        Case acLBGetColumnCount    ' Get number of columns.
            ReturnVal = 3

        Case acLBGetColumnWidth    ' Column width.
            If col = 0 Then
                ReturnVal = 0
            Else
            ' -1 forces use of default width.
                ReturnVal = -1
            End If

        Case acLBGetValue                    ' Get data.

            If Not List Is Nothing Then
                If row >= List.Count Then
                    ReturnVal = totalRow(List, col)
                Else
                    ReturnVal = body(List, row, col)
                End If
            Else
                ReturnVal = totalRow(List, col)
            End If
        Case acLBEnd                        ' End.
    End Select

    source = ReturnVal
End Function

'  ****************************** Form2 Code
Option Compare Database

Private List As Collection

Public Sub edit()
    Dim thing As BillDef
    Dim key As String

    Set List = New Collection

    Set thing = New BillDef
    thing.Id = 1
    thing.Name = "Foo"
    thing.Amount = 10.23
    key = thing.Id
    List.Add thing, key

    Set thing = New BillDef
    thing.Id = 2
    thing.Name = "Bar"
    thing.Amount = 30.2
    key = thing.Id
    List.Add thing, key

    Form_Form1.Visible = False
    Me.List0.Requery
    Me.Visible = True
End Sub

Function billsSource _
( _
    fld As Control, _
    Id As Variant, _
    row As Variant, _
    col As Variant, _
    code As Variant _
) As Variant
    Dim ReturnVal As Variant
    ReturnVal = Null

    Select Case code
        Case acLBInitialize                ' Initialize.
            If IsNull(billList) Then
                ReturnVal = False
            Else
                ReturnVal = True
            End If

        Case acLBOpen                        ' Open.
            ' Generate unique ID for control.
            ReturnVal = Timer

        Case acLBGetRowCount            ' Get number of
rows.
            If Not List Is Nothing Then
                ReturnVal = List.Count + 1
            Else
                ReturnVal = 1
            End If

        Case acLBGetColumnCount    ' Get number of columns.
            ReturnVal = 3

        Case acLBGetColumnWidth    ' Column width.
            If col = 0 Then
                ReturnVal = 0
            Else
            ' -1 forces use of default width.
                ReturnVal = -1
            End If

        Case acLBGetValue                    ' Get data.
            If Not List Is Nothing Then
                If row >= billList.Count Then
                    ReturnVal = totalRow(List, col)
                Else
                    ReturnVal = body(List, row, col)
                End If
            Else
                ReturnVal = totalRow(List, col)
            End If
        Case acLBEnd                        ' End.
    End Select

    billsSource = ReturnVal
End Function

' ******************************** Form3 Code
Option Compare Database

Private doctorList As Collection

Public Sub edit()
    Dim thing As IndexText
    Dim key As String

    Set doctorList = New Collection

    Set thing = New IndexText
    thing.start 1, "Foo"
    key = thing.index
    doctorList.Add thing, key

    Set thing = New IndexText
    thing.start 2, "Bar"
    key = thing.index
    doctorList.Add thing, key

    List0.Requery
    Form_Form1.Visible = False
    Me.Visible = True
End Sub

Function doctorsSource _
( _
    fld As Control, _
    Id As Variant, _
    row As Variant, _
    col As Variant, _
    code As Variant _
) As Variant
    Dim ReturnVal As Variant
    ReturnVal = Null

    Select Case code
        Case acLBInitialize                ' Initialize.
            If doctorList Is Nothing Then
                ReturnVal = False
            ElseIf doctorList.Count = 0 Then
                ReturnVal = False
            Else
                ReturnVal = True
            End If

        Case acLBOpen                        ' Open.
            ' Generate unique ID for control.
            ReturnVal = Timer

        Case acLBGetRowCount            ' Get number of
rows.
            ReturnVal = doctorList.Count

        Case acLBGetColumnCount    ' Get number of columns.
            ReturnVal = 2

        Case acLBGetColumnWidth    ' Column width.
            If col = 0 Then
                ReturnVal = 0
            Else
            ' -1 forces use of default width.
                ReturnVal = -1
            End If

        Case acLBGetValue                    ' Get data.
            Dim value As IndexText

            Set value = doctorList.Item(row + 1)

            Select Case col
                Case 0
                    ReturnVal = value.index
                Case 1
                    ReturnVal = value.text
            End Select

        Case acLBEnd                        ' End.
    End Select

    doctorsSource = ReturnVal
End Function

'***************************************** Module1 Code

Option Compare Database

Public Function body(List As Collection, row As Variant,
col As Variant) As Variant
    Dim theRow As Integer
    Dim data As BillDef

    Set data = List.Item(row + 1)

    Select Case col
        Case 0
            body = data.Id
        Case 1
            body = data.Name
        Case 2
            body = data.Amount
    End Select
End Function

Public Function totalRow(List As Collection, col As
Variant) As Variant
    Select Case col
        Case 0
            totalRow = 0
        Case 1
            totalRow = "Total"
        Case 2
            totalRow = totalBill(List)
    End Select
End Function

Public Function totalBill(List As Collection) As Currency
    Dim def As BillDef
    Dim result As Currency

    result = 0

    If Not List Is Nothing Then
        For Each def In List
            result = result + def.Amount
        Next
    End If

    totalBill = result
End Function

' **************************** Class BillDef Code

Option Compare Database
Option Explicit

Public Id As Integer
Public Name As String
Public Amount As Currency

' ********************************  Class IndexText Code

Option Compare Database
Option Explicit

Private indexVal As Integer
Private textVal As String

Public Sub start(indexArg As Integer, textArg As String)
    indexVal = indexArg
    textVal = textArg
End Sub

Public Property Get index() As Integer
    index = indexVal
End Property

Public Property Get text() As String
    text = textVal
End Property

Public Property Let text(value As String)
    textVal = value
End Property



Mon, 29 Aug 2005 02:12:13 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. ListBox requery GPF

2. Requery, requery, requery

3. Control.Requery requires save before requery

4. Requery Form vs Requery Control

5. .Requery does not requery listbox

6. requery doesnt always requery

7. Outlook 2002 & Team Folders revisited

8. Multiple Accounts Revisited

9. Blank Email - Revisited

10. MS Outlook security update revisited


 
Powered by phpBB® Forum Software © phpBB Group