Auto select first item in list box after selecting tab.

J

JK

Any idea why this doesn't work? Maybe there is another way?

After a user selects a tab, I want to have the application auto-select the
first item in the list box. It works on the form load event but that's just
the first tab.

Private Sub pgMiscReports2_Click()
' auto-select the first item in the list box
Me!lstReports2.Selected(0) = True
Me.cmdOpenReports2.SetFocus
End Sub


Any help would be appreciated.

Thx,
Jason
 
F

fredg

Any idea why this doesn't work? Maybe there is another way?

After a user selects a tab, I want to have the application auto-select the
first item in the list box. It works on the form load event but that's just
the first tab.

Private Sub pgMiscReports2_Click()
' auto-select the first item in the list box
Me!lstReports2.Selected(0) = True
Me.cmdOpenReports2.SetFocus
End Sub

Any help would be appreciated.

Thx,
Jason

Me!lstReports2.ListIndex = 0
 
D

Dale Fye

When you are working with a Tab control, you best bet is to use the tabs
Change event to do this type of thing:

Private Sub tab_MyTab_Change

'I like to refer to the caption rather than the page index
SELECT CASE me.tab_MyTab.pages(me.tab_MyTab).Caption
Case 1 "Caption1"
'some code here
Case "Misc Reports"
me.lstReports2 = me.lstReports.column(0, 0)
me.cmdOpenReporst2.SetFocus
Case Else
End Select

End sub

When you "select" the list item the way you are attempting to do, you are
not actually setting it's value. I prefer to actually set the value.
--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
D

Dale Fye

Fred,

That won't work unless the listbox has the focus.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
J

JK

I’m having trouble making your code work. I’m getting an error after Case 1
“Caption1.†I’m putting the first tab's caption in that field. The error I’m
getting says Expected: End of Statement.

My form has six tabs.

Tab Control Name: TabCtl8

Tab #1
Name: pgMiscReports
Caption: Re&ports (1)
List Box: lstForms3
Open Button: cmdOpenForm2

Tab #2
Name: pgMiscReports2
Caption: Repor&ts (2)
List Box: lstReports2
Open Button: cmdOpenReports2

This is how I started, but I must be doing something wrong?

Private Sub TabCtl8_Change()
'I like to refer to the caption rather than the page index
Select Case Me.TabCtl8.Pages(Me.TabCtl8).Caption
Case 1 "Re&ports (1)" ‘THIS IS WHERE I GET AN ERROR
'some code here
Case "pgMiscReports"
Me.lstForms3 = Me.lstForms3.Column(0, 0)
Me.cmdOpenForm2.SetFocus
Case Else
End Select


Thx.
Jason
 
J

JK

I’m having trouble making your code work. I’m getting an error after Case 1
“Caption1.†I’m putting the first tab's caption in that field. The error I’m
getting says Expected: End of Statement.

My form has six tabs.

Tab Control Name: TabCtl8

Tab #1
Name: pgMiscReports
Caption: Re&ports (1)
List Box: lstForms3
Open Button: cmdOpenForm2

Tab #2
Name: pgMiscReports2
Caption: Repor&ts (2)
List Box: lstReports2
Open Button: cmdOpenReports2

This is how I started, but I must be doing something wrong?

Private Sub TabCtl8_Change()
'I like to refer to the caption rather than the page index
Select Case Me.TabCtl8.Pages(Me.TabCtl8).Caption
Case 1 "Re&ports (1)" ‘THIS IS WHERE I GET AN ERROR
'some code here
Case "pgMiscReports"
Me.lstForms3 = Me.lstForms3.Column(0, 0)
Me.cmdOpenForm2.SetFocus
Case Else
End Select


Thx.
Jason
 
J

JK

I’m having trouble making your code work. I’m getting an error after Case 1
“Caption1.†I’m putting the first tab's caption in that field. The error I’m
getting says Expected: End of Statement.

My form has six tabs.

Tab Control Name: TabCtl8

Tab #1
Name: pgMiscReports
Caption: Re&ports (1)
List Box: lstForms3
Open Button: cmdOpenForm2

Tab #2
Name: pgMiscReports2
Caption: Repor&ts (2)
List Box: lstReports2
Open Button: cmdOpenReports2

This is how I started, but I must be doing something wrong?

Private Sub TabCtl8_Change()
'I like to refer to the caption rather than the page index
Select Case Me.TabCtl8.Pages(Me.TabCtl8).Caption
Case 1 "Re&ports (1)" ‘THIS IS WHERE I GET AN ERROR
'some code here
Case "pgMiscReports"
Me.lstForms3 = Me.lstForms3.Column(0, 0)
Me.cmdOpenForm2.SetFocus
Case Else
End Select


Thx.
Jason
 
J

JK

I’m having trouble making your code work. I’m getting an error after Case 1
“Caption1.†I’m putting the first tab's caption in that field. The error I’m
getting says Expected: End of Statement.

My form has six tabs.

Tab Control Name: TabCtl8

Tab #1
Name: pgMiscReports
Caption: Re&ports (1)
List Box: lstForms3
Open Button: cmdOpenForm2

Tab #2
Name: pgMiscReports2
Caption: Repor&ts (2)
List Box: lstReports2
Open Button: cmdOpenReports2

This is how I started, but I must be doing something wrong?

Private Sub TabCtl8_Change()
'I like to refer to the caption rather than the page index
Select Case Me.TabCtl8.Pages(Me.TabCtl8).Caption
Case 1 "Re&ports (1)" ‘THIS IS WHERE I GET AN ERROR
'some code here
Case "pgMiscReports"
Me.lstForms3 = Me.lstForms3.Column(0, 0)
Me.cmdOpenForm2.SetFocus
Case Else
End Select


Thx.
Jason
 
D

Dale Fye

Change:
Case 1 "Re&ports (1)" ‘THIS IS WHERE I GET AN ERROR
to:
Case "Re&ports (1)"


If you prefer, you can use the controls name:

Select Case me.TabCtl8.Pages(me.TabCtl8).Name
Case "pgMiscReports"
msgbox "pgMiscReports"
Case "pgMiscReports2"
msgbox "pgMiscReports2"
Case else
msgbox "else"
End Select
--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 

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

Top