[AccessD] Form hangs when setting listbox selected index

Christopher Jeris cjeris at fas.harvard.edu
Tue Jun 12 13:28:58 CDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This may be a novice question, but I'm quite confused.

Fully updated Access XP on Windows XP.

I have created a form with a single listbox control, List0.
There is a table Table1 with a single TEXT(50) field field1, and a query
Query1 whose content is SELECT field1 FROM Table1 .

The form's class module has the following content:

Option Compare Database

Private Sub Form_Open(Cancel As Integer)
    Dim qd As DAO.QueryDef
    Dim rs As DAO.Recordset
    Set qd = CurrentDb.QueryDefs("Query1")
    Set rs = qd.OpenRecordset(dbOpenDynaset, dbReadOnly)
    If rs.BOF Then ' no records
        Cancel = True
    Else
        Set Me!List0.Recordset = rs
        Me!List0.Selected(0) = True
    End If
    Set rs = Nothing
    Set qd = Nothing
End Sub

(I know DAO is ancient, but the docs I learned from are all of Access 97
vintage, and I haven't learned how to work ADO yet.  Other DAO code in
this project works fine.)

The problem I observe is that after
        Me!List0.Selected(0) = True
the form hangs: all controls on it become unresponsive.  The form can be
closed normally and Access itself survives.

What I want to do is just highlight the first item in the listbox by
default.  What's going on here?

Thanks,
Chris Jeris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGbuXq5ICCNV0oGWARAuSAAJ9/ub1vUNPqZNK4rzTZPzl35aXnOACfVt1W
3OThlbDJ93d4lQyBafcX0I0=
=kyG4
-----END PGP SIGNATURE-----



More information about the AccessD mailing list