Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Select 1st Item

Geek News

Select 1st Item
"CJ" <private[ at ]newsgroups.com> 11/14/2008 9:28:43 PM
Hi again Groupies

When the listbox on my form receives the focus, I would like it's first
record to be selected. How do I make this happen with code?

I have tried:

Private Sub lstShopInventory_GotFocus()
Dim rst As DAO.Recordset
Me.Refresh
Set rst = Me.Recordset
rst.GetRows 1
End Sub

....nothing happened....

--
Thanks for taking the time!

CJ
---------------------------------------------------------
Know thyself, know thy limits....know thy newsgroups!

Re: Select 1st Item
"CJ" <private[ at ]newsgroups.com> 11/14/2008 9:32:08 PM
Never mind, I got it.

Me.Refresh
SendKeys "^{HOME}"

--
Thanks for taking the time!

CJ
---------------------------------------------------------
Know thyself, know thy limits....know thy newsgroups!
"CJ" <private[ at ]newsgroups.com> wrote in message
news:A600E2B8-BD92-43CD-BE3E-7E320A3BF2D6[ at ]microsoft.com...
[Quoted Text]
> Hi again Groupies
>
> When the listbox on my form receives the focus, I would like it's first
> record to be selected. How do I make this happen with code?
>
> I have tried:
>
> Private Sub lstShopInventory_GotFocus()
> Dim rst As DAO.Recordset
> Me.Refresh
> Set rst = Me.Recordset
> rst.GetRows 1
> End Sub
>
> ...nothing happened....
>
> --
> Thanks for taking the time!
>
> CJ
> ---------------------------------------------------------
> Know thyself, know thy limits....know thy newsgroups!

Re: Select 1st Item
"Stuart McCall" <smccall[ at ]myunrealbox.com> 11/14/2008 10:36:17 PM
"CJ" <private[ at ]newsgroups.com> wrote in message
news:3CBB459B-A9D8-431A-8210-ECCBD7E8EA12[ at ]microsoft.com...
[Quoted Text]
> Never mind, I got it.
>
> Me.Refresh
> SendKeys "^{HOME}"

Ugh! PLEASE don't go with that. Sendkeys is notoriously unreliable. Also it
will be quietly ignored under Vista.

The correct way to select the 1st item is:

Me.MyListbox.Value = Me.MyListbox.ItemData(0)


Re: Select 1st Item
"tkelley via AccessMonster.com" <u47368[ at ]uwe> 11/14/2008 10:49:07 PM
Just for grins, does

me.lstShopInventory.listindex=0

or

me.lstShopInventory.listindex=0

work?

CJ wrote:
[Quoted Text]
>Never mind, I got it.
>
>Me.Refresh
>SendKeys "^{HOME}"
>
>> Hi again Groupies
>>
>[quoted text clipped - 11 lines]
>>
>> ...nothing happened....

--
Message posted via http://www.accessmonster.com

Re: Select 1st Item
CJ 11/15/2008 12:34:01 AM
It worked for me.
--
Thanks for the brainwaves!

CJ
I blame the parents........


"tkelley via AccessMonster.com" wrote:

[Quoted Text]
> Just for grins, does
>
> me.lstShopInventory.listindex=0
>
> or
>
> me.lstShopInventory.listindex=0
>
> work?
>
> CJ wrote:
> >Never mind, I got it.
> >
> >Me.Refresh
> >SendKeys "^{HOME}"
> >
> >> Hi again Groupies
> >>
> >[quoted text clipped - 11 lines]
> >>
> >> ...nothing happened....
>
> --
> Message posted via http://www.accessmonster.com
>
>
Re: Select 1st Item
CJ 11/15/2008 12:35:00 AM
I changed it, thanks for the tip.........however, it was working on my Vista
machine with A2K7
--
Thanks for the brainwaves!

CJ
I blame the parents........


"Stuart McCall" wrote:

[Quoted Text]
> "CJ" <private[ at ]newsgroups.com> wrote in message
> news:3CBB459B-A9D8-431A-8210-ECCBD7E8EA12[ at ]microsoft.com...
> > Never mind, I got it.
> >
> > Me.Refresh
> > SendKeys "^{HOME}"
>
> Ugh! PLEASE don't go with that. Sendkeys is notoriously unreliable. Also it
> will be quietly ignored under Vista.
>
> The correct way to select the 1st item is:
>
> Me.MyListbox.Value = Me.MyListbox.ItemData(0)
>
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net