Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Focus to previous control in list box 1

Status
Not open for further replies.

mpm32

Technical User
Feb 19, 2004
130
US
I have a form that has a list box and a subform linked to the selection in the listbox.

I currently have it so that when the user clicks their choice on the listbox, the subform record come up. They need to click a checkbox. This checkbox populates a field with the username (Environ).

I am trying to figure out how to return the focus back to the selection that they originally clicked on in the list box.

The users will be going down the selections in the listbox, and checking complete in the subform. In order to speed this process up, I need to have the focus revert back to the originally clicked listbox item. (Or even better, the next record down on the list.)

I have looked at and tried to use the Screen.PreviousControl but it doesn't seem to work for me.

To test it I put =[Screen].[PreviousControl].[Name]in a text box. It shows the name of the listbox "List0" and the control "Completed" when I click them alternately. But I can't figure out how to put this into practice doing what I need it to.

Any suggestions?

Thanks

Mark
 
What about something like this (VBA code)?
Screen.PreviousControl.SetFocus

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You can select the next item like so:

Code:
    Me.lstList.SetFocus
    Me.lstList.Selected(Me.lstList.ListIndex + 1) = True
 
I tried this;

On the subform control [completed]

Code:
Private Sub Completed_Click()

Screen.PreviousControl.SetFocus
    
End Sub

The focus did not return to the listbox from the subform.

I also tried this;

Code:
Me.List0.SetFocus
Me.List0.Selected(Me.List0.ListIndex + 1) = True

My listbox is named List0. I get an error; Compile Error: Method or data member not found.

I'm obviously missing something or I am putting the code in the wrong place.
 
Where is the listbox, the main form or the subform?
 
The listbox is on the main form.

Thanks
 
You seem to be running the code on the subform, so try:

Me.Parent.List0.SetFocus
Me.Parent.List0.Selected(Me.List0.ListIndex + 1) = True

 
I tried putting that in the on click procedure of the control [completed] and I get the same error; Compile Error: Method or data member not found.

Code:
Private Sub Completed_Click()

Me.Parent.List0.SetFocus
Me.Parent.List0.Selected(Me.List0.ListIndex + 1) = True

End Sub

Could there be a reference I am missing?
 
Where is the control 'Completed'? Which line gives the error?
 
The control completed is on the subform. It is a checkbox.

It highlights in yellow the line "Private Sub Completed_Click()"

It also highlights in blue the 2nd List0 in this line "Me.Parent.List0.Selected(Me.List0.ListIndex + 1) = True"

 
Me.Parent.List0.Selected(Me[!].Parent[/!].List0.ListIndex + 1) = True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
My fault:

Me.Parent.List0.Selected(Me.[red]Parent[/red].List0.ListIndex + 1) = True
 
In fact I'd try this:
Code:
Private Sub Completed_Click()
Me.Parent.SetFocus
With Me.Parent.List0
  .SetFocus
  .Value = .ItemData(.ListIndex + 1)
End With
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ah, that works great PHV. It brings the focus back to the listbox. For some reason though, it will not cycle down to the next item in the list.

This worked though;

Code:
Private Sub Completed_Click()
Me.Parent.SetFocus
With Me.Parent.List0
  .SetFocus
  .Value = .ItemData(.ListIndex + 2)
End With
End Sub

It moves down the list with the +2 the +1 kept it on the same list item.

Thanks for both of your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top