Focus in a list box

S

Simon

hi,

I have a list box(contain only a field) in a form, when the user clicks the
list box, then, the form display the selected record. My question is when the
user moves the focus of the record to the next,previous (using buttons of the
form)...., how can i set the focus in the same value into the list box ?

Thanks
 
S

Stuart McCall

Simon said:
hi,

I have a list box(contain only a field) in a form, when the user clicks
the
list box, then, the form display the selected record. My question is when
the
user moves the focus of the record to the next,previous (using buttons of
the
form)...., how can i set the focus in the same value into the list box ?

Thanks

Me.ListboxName.Value = Me!KeyField

Replace the obvious. Use this in the OnCurrent event of your form.
 
S

Simon

hi,

i put the code in the OnCurrent event of the form but it still does not work

If Me.Recordset.RecordCount > 0 And IsNull(Me!Date_1) = False Then
Me!List_Of_Records.SetFocus
Me!List_Of_Records.Value = Me!Date_1.Value
End If

Ο χÏήστης "Stuart McCall" έγγÏαψε:
 
S

Stuart McCall

Simon said:
hi,

i put the code in the OnCurrent event of the form but it still does not
work

If Me.Recordset.RecordCount > 0 And IsNull(Me!Date_1) = False Then
Me!List_Of_Records.SetFocus
Me!List_Of_Records.Value = Me!Date_1.Value
End If

? ??????? "Stuart McCall" ???????:

So Me!List_Of_Records is a list of dates? You're selecting records on a date
field? Unusual, but you must have a reason. If that's the case then there's
no reason your code doesn't work. So I suspect that isn't the case. Look
carefully. The field you should be referring to is the *primary key* field
of the form's recordset. That should be the field the listbox is bound to
(whether visible or not).

The point is that setting the .Value property of the listbox will 'move' the
list to the corresponding entry.

HTH
 
S

Simon

Hi,

I changed the code to:

Dim rs As Object
If Me.Recordset.RecordCount > 0 And IsNull(Me!Fld_Date_1) = False Then
Me!List_Of_Records.Value = Me!Fld_Date_1D.Value
Set rs = Me.Recordset.Clone
rs.FindFirst "Fld_Date_1 = #" & Format(Me![List_Of_Records],
"dd\/mm\/yyyy") & "#"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
rs.Close
Set rs = Nothing
End If

and it worked.

Thanks for your help.

Ο χÏήστης "Stuart McCall" έγγÏαψε:
 

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