Hale, Jim
Jim.Hale at FleetPride.com
Tue Jun 12 13:53:01 CDT 2007
It appears you are missing part of the if test. Try
If rs.BOF and rs.EOF then
HTH
Jim Hale
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Christopher
Jeris
Sent: Tuesday, June 12, 2007 1:29 PM
To: accessd at databaseadvisors.com
Subject: [AccessD] Form hangs when setting listbox selected index
-----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-----
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
***********************************************************************
The information transmitted is intended solely for the individual or
entity to which it is addressed and may contain confidential and/or
privileged material. Any review, retransmission, dissemination or
other use of or taking action in reliance upon this information by
persons or entities other than the intended recipient is prohibited.
If you have received this email in error please contact the sender and
delete the material from any computer. As a recipient of this email,
you are responsible for screening its contents and the contents of any
attachments for the presence of viruses. No liability is accepted for
any damages caused by any virus transmitted by this email.