Results 1 to 3 of 3

Thread: Combo Box text disappears!

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Combo Box text disappears!

    I have a combo box that's supposed to show all values in a given database. The procedure works fine until it gets to the end, then for some reason the combo box loses its text. The list items are there, it just no longer shows the item I selected. I ran a quick debug, and it happens right on the first Exit Sub (the one before the error handler.)

    Code:
    Private Sub MasterControl_Click()
        Set fso = New FileSystemObject
        On Error GoTo ErrorHandler
        MasterControl.Text = Replace(MasterControl.Text, " ", "")
        If fso.FileExists(App.Path & "\Databases\" & MasterControl.Text & ".mdb") = False Then
            For i = 0 To MasterControl.ListCount
                If MasterControl.Text = MasterControl.List(i) Then
                    MasterControl.RemoveItem i
                End If
            Next i
            Set rs = New ADODB.Recordset
            RecordSource = "SELECT * FROM Headers ORDER BY Name"
            ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Databases\Headers.mdb"
            rs.Open RecordSource, ConnectionString, adOpenKeyset, adLockOptimistic
            If Not rs.BOF Then
                rs.MoveFirst
            End If
            For i = 1 To rs.RecordCount
                If rs!Name = MasterControl.Text Then
                    rs.Delete adAffectCurrent
                Else
                    rs.MoveNext
                End If
                If rs.EOF = True Then Exit For
            Next i
        End If
        OrganizerDatabase.ListItems.Clear
        Set rs = New Recordset
        Set Win32Script = CreateObject("WScript.Shell")
        For i = 0 To Data.Count - 1
            Data(i).Locked = False
            Data(i).BackColor = vbWhite
        Next i
        RecordSource = "SELECT * FROM " & MasterControl.Text & " ORDER BY SiteName"
        ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Databases\" & MasterControl.Text & ".mdb"
        Win32Script.RegWrite "HKEY_CURRENT_USER\Software\" & App.Title & "\CurrentSelectedItem", MasterControl.Text
        rs.Open RecordSource, ConnectionString, adOpenKeyset, adLockOptimistic
        If rs.BOF = False Then
            rs.MoveFirst
        End If
        For i = 1 To rs.RecordCount
            If rs.EOF = True Then Exit For
            OrganizerDatabase.ListItems.Add , , rs!SiteName
            rs.MoveNext
        Next i
        Set fso = Nothing
        Set rs = Nothing
        Set Win32Script = Nothing
        Exit Sub
    ErrorHandler:
        MsgBox "Error #" & Err.Number & ":  " & Err.Description, vbCritical, "Program Error"
        Exit Sub
    End Sub

  2. #2

  3. #3

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Re: Combo Box text disappears!

    That code results in an error "Out of stack space" in my recordset opening routine.

    rs.Open RecordSource, ConnectionString, adOpenKeyset, adLockOptimistic

    Take the code out, the error goes away. I ran a quick Google search on the issue, and it says the limits of the stack have been exceeded, and to try declaring the variables inside a module, so I'll try that and see what happens.

    Nope, it's not working. The combo box deletes its text right where I thought it was doing it - after I exit the sub. It's weird, because I don't have it programmed to do anything after it exits the sub, it's like this program's got a mind of its own. After a little debugging, I found out something is physically changing the contents of the combo box. (I put in a MsgBox call to see if the _Change event triggers, and sure enough it does.)
    Last edited by hothead; Aug 9th, 2007 at 09:42 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width