Listbox Default Value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a form from which the user selects a date from a listbox. The
listbox values are generated from a sql statement in the form's OnOpen event.
I would like the listbox to have the maximum (i.e. latest) date as its value
when the form opens up. That much I can accomplish.

The problem is having the listbox appear as though the latest date has been
selected. The latest date is always row 0. I have tried using the
"Selected" property which does not work. Actually does not work is
inaccurate. It prevents ANYTHING from happening on the form. I cannot
select other dates, I cannot click on my tabs, I cannot click on buttons.
The only way out is by going to design view and close from there. Is this an
error on my part or (I hate to use the b-word but) a bug?

Thanks,

The code follows:

Private Sub Form_Open(Cancel As Integer)
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Select max([allocation_date]) from
[INVS_pacesmtb History]")
Me.AllocDate.Value = Format(rst.Fields(0).Value, "yyyy-mm-dd")
'*******This is the bad line*******
Me.AllocDate.Selected(0) = True
'***************************
rst.Close
Set dbs = Nothing
End Sub
 
Nevermind. If you put the line:

me.allocdate.selected(0) = true

into the form's Current event it works. I did some more reading, and found
that with the listbox (I don't know how to say this properly) it is not
completely done "loading" (?) in the OnOpen event, and any referencing to its
rows cannot be made yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

help with Code 1
Invalid Use of Null 3
Run Query on Subform Using VBA Macro Button 1
Listbox problem 4
Access Cannot select items in listbox 1
Message from Access 2007 on sub function 3
Code won't run 1
Make table from recordset 2

Back
Top