Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

My Last Post about List box solution didn't work..Try to exp bette

0 views
Skip to first unread message

BrianPaul

unread,
Sep 18, 2006, 9:24:01 PM9/18/06
to
Try to post the question more efficient this time.

I have a listbox on a form that has for example the following dates:

Jan 1
jan 3
jan 5
jan 7

When I select one of these days for example Jan 3. another listbox opens and
lists all appointments for that day.

Question: If today was january ,6 (I have no Jan 6 in the above example) I
want to be able to open the form and set the focus to the listbox and
highlight Jan 7 since its the next date. I tried to use <Date() and it
erased all the listbox entries prior to todays date. Can it be Done? and how?

Thanks.

Dirk Goldgar

unread,
Sep 18, 2006, 9:41:38 PM9/18/06
to
"BrianPaul" <Bria...@discussions.microsoft.com> wrote in message
news:33EB19C5-7883-47C3...@microsoft.com

Try the following completely untested air code. I'm assuming that you
want this to happen every time the form is opened, so I'll put the code
in the form's Load event. It might work in the Open event, too, but I
chose the Load event to make sure all controls have been instantiated.
I'm also assuming that the rows in the list box are either displaying
full dates, not just month and day, or else they only contain dates in
the current year.

'----- start of air code -----
Private Sub Form_Load()

Dim lRow As Long

With Me.lstMyListBox ' ** substitute name

For lRow = Abs(.ColumnHeads) To (.ListCount - 1)
If CDate(.ItemData(lRow)) >= Date() Then
.Value = .ItemData(lRow)
Call lstMyListBox_AfterUpdate ' ** substitute name
Exit For
End If
Next lRow

End With

End Sub
'----- end of air code -----

NOTE: On the lines marked " ** substitute name", substitute the name of
your list box for "lstMyListBox".

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


BrianPaul

unread,
Sep 18, 2006, 11:13:02 PM9/18/06
to
Thanks Dirk, You have always came through.

BrianPaul

unread,
Sep 20, 2006, 1:31:02 PM9/20/06
to
Bummer, Get a data type mismatch error. I checked to settings on the field
in the listbox query and it is a date. I will keep trying to work with it to
see if I can get it to work.
Thanks

Dirk Goldgar

unread,
Sep 21, 2006, 11:43:02 AM9/21/06
to
"BrianPaul" <Bria...@discussions.microsoft.com> wrote in message
news:E1F90C87-92F6-4C05...@microsoft.com

> Bummer, Get a data type mismatch error. I checked to settings on the
> field in the listbox query and it is a date. I will keep trying to
> work with it to see if I can get it to work.

What is the SQL of the list box's RowSource query? Which column is the
bound column?

Also, which line of code is giving the type mismatch error?

0 new messages