Listbox problem

  • Thread starter Niklas Östergren
  • Start date
N

Niklas Östergren

Hi!

I have never used listboxes before (haven´t hade any reason untill now).

I have a form <frmAddAttachmentsToEmailMsg> in which I have one combobox
<cboSearchFileName> and one listbox <lstSelectFileName>. In the listbox
AfterUpdate_Event I have following code:

'==================================
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[DocumentID] = " & Str(Nz(Me![lstSelectFileName], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
'==================================

When I mark a record in the listbox the record is highlighted, which is
exactly what I want.

Now to my problem:
I use the combobox to search for records which I then want to be highlited
(selected) in the listbox. When I select a record in the combobox the form
is uppdated with the record that I have searched for. BUT the record is NOT
highlighted in the listbox, which I want it to be. Since it´s much easyer to
see which record that have been selected.

I have following code in the combobox AfterUpdate_Event
'=======================================
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[DocumentID] = " & Str(Nz(Me![cboSearchFileName], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Me.lstSelectFileName.SetFocus
Me.cboSearchFileName = ""
'========================================

If there is abetter way of doing this then to use a combobox please let me
know.

One way could be to use a texbox where the user types in the name of the
record that they want to be highlighted in the listbox and that the listbox
highlight the record that match the textbox on the fly. But this may not be
a good idéa. And I surtanly doesn´t know how to implement it.

TIA!
// Niklas
 
G

Guest

Hi Niklas,

To select the items in a list box based on the entry in a combo box you can
use this:

Dim i
For i = 0 To YourList.ListCount
If YourList.ItemData(i) = YourComboBox Then
YourList.Selected(i) = True
End If
Next i

HTH
Jason
 
N

Niklas Östergren

Jason!

Thank´s a lot!

It works the way I want, accept for one thing!

If I type in the file name and use <Enter> to select record in my combobox
then it set´s focus to my listbox. But if I uses the mous to select a record
I either get run time error 2110 OR if I delete the code where I set focus
on my listbox the combobox stays Open until I click somewhere else on the
form.

In my combo´s OnChange_Event I have following code:

Me!cboSearchFileName.Dropdown

I have tryed to first set focus to another control in my form
<txtDocumentPath> and THEN set focus to my listbox but I still get this run
time error.

Any idéas?

Thank´s a lot for your help with the listbox. What I can se I need to read
more about how they work.

// Niklas


Jason Rice said:
Hi Niklas,

To select the items in a list box based on the entry in a combo box you
can
use this:

Dim i
For i = 0 To YourList.ListCount
If YourList.ItemData(i) = YourComboBox Then
YourList.Selected(i) = True
End If
Next i

HTH
Jason

Niklas Östergren said:
Hi!

I have never used listboxes before (haven´t hade any reason untill now).

I have a form <frmAddAttachmentsToEmailMsg> in which I have one combobox
<cboSearchFileName> and one listbox <lstSelectFileName>. In the listbox
AfterUpdate_Event I have following code:

'==================================
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[DocumentID] = " & Str(Nz(Me![lstSelectFileName], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
'==================================

When I mark a record in the listbox the record is highlighted, which is
exactly what I want.

Now to my problem:
I use the combobox to search for records which I then want to be
highlited
(selected) in the listbox. When I select a record in the combobox the
form
is uppdated with the record that I have searched for. BUT the record is
NOT
highlighted in the listbox, which I want it to be. Since it´s much easyer
to
see which record that have been selected.

I have following code in the combobox AfterUpdate_Event
'=======================================
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[DocumentID] = " & Str(Nz(Me![cboSearchFileName], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Me.lstSelectFileName.SetFocus
Me.cboSearchFileName = ""
'========================================

If there is abetter way of doing this then to use a combobox please let
me
know.

One way could be to use a texbox where the user types in the name of the
record that they want to be highlighted in the listbox and that the
listbox
highlight the record that match the textbox on the fly. But this may not
be
a good idéa. And I surtanly doesn´t know how to implement it.

TIA!
// Niklas
 
G

Guest

This should work, however, there may be a better solution out there.

You can send the F4 key to the system to close the dropdown. In the form
view, you can perform the dropdown by pressing the F4 key and close it again
with the same key. You can use the SendKeys function to emulate keyboard
input.

You can use:

SendKeys "{F4}"

This should close your dropdown list and leave the focus with the combobox.

HTH
Jason

Niklas Östergren said:
Jason!

Thank´s a lot!

It works the way I want, accept for one thing!

If I type in the file name and use <Enter> to select record in my combobox
then it set´s focus to my listbox. But if I uses the mous to select a record
I either get run time error 2110 OR if I delete the code where I set focus
on my listbox the combobox stays Open until I click somewhere else on the
form.

In my combo´s OnChange_Event I have following code:

Me!cboSearchFileName.Dropdown

I have tryed to first set focus to another control in my form
<txtDocumentPath> and THEN set focus to my listbox but I still get this run
time error.

Any idéas?

Thank´s a lot for your help with the listbox. What I can se I need to read
more about how they work.

// Niklas


Jason Rice said:
Hi Niklas,

To select the items in a list box based on the entry in a combo box you
can
use this:

Dim i
For i = 0 To YourList.ListCount
If YourList.ItemData(i) = YourComboBox Then
YourList.Selected(i) = True
End If
Next i

HTH
Jason

Niklas Östergren said:
Hi!

I have never used listboxes before (haven´t hade any reason untill now).

I have a form <frmAddAttachmentsToEmailMsg> in which I have one combobox
<cboSearchFileName> and one listbox <lstSelectFileName>. In the listbox
AfterUpdate_Event I have following code:

'==================================
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[DocumentID] = " & Str(Nz(Me![lstSelectFileName], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
'==================================

When I mark a record in the listbox the record is highlighted, which is
exactly what I want.

Now to my problem:
I use the combobox to search for records which I then want to be
highlited
(selected) in the listbox. When I select a record in the combobox the
form
is uppdated with the record that I have searched for. BUT the record is
NOT
highlighted in the listbox, which I want it to be. Since it´s much easyer
to
see which record that have been selected.

I have following code in the combobox AfterUpdate_Event
'=======================================
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[DocumentID] = " & Str(Nz(Me![cboSearchFileName], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Me.lstSelectFileName.SetFocus
Me.cboSearchFileName = ""
'========================================

If there is abetter way of doing this then to use a combobox please let
me
know.

One way could be to use a texbox where the user types in the name of the
record that they want to be highlighted in the listbox and that the
listbox
highlight the record that match the textbox on the fly. But this may not
be
a good idéa. And I surtanly doesn´t know how to implement it.

TIA!
// Niklas
 
N

Niklas Östergren

Jason!

Great, work´s just like a train!
I just wonder why my code doesn´t work in this case? Well, now I have
something that do work´s and that´s what matters right now!

Thank´s a lot Jason!

// Niklas


Jason Rice said:
This should work, however, there may be a better solution out there.

You can send the F4 key to the system to close the dropdown. In the form
view, you can perform the dropdown by pressing the F4 key and close it
again
with the same key. You can use the SendKeys function to emulate keyboard
input.

You can use:

SendKeys "{F4}"

This should close your dropdown list and leave the focus with the
combobox.

HTH
Jason

Niklas Östergren said:
Jason!

Thank´s a lot!

It works the way I want, accept for one thing!

If I type in the file name and use <Enter> to select record in my
combobox
then it set´s focus to my listbox. But if I uses the mous to select a
record
I either get run time error 2110 OR if I delete the code where I set
focus
on my listbox the combobox stays Open until I click somewhere else on the
form.

In my combo´s OnChange_Event I have following code:

Me!cboSearchFileName.Dropdown

I have tryed to first set focus to another control in my form
<txtDocumentPath> and THEN set focus to my listbox but I still get this
run
time error.

Any idéas?

Thank´s a lot for your help with the listbox. What I can se I need to
read
more about how they work.

// Niklas


Jason Rice said:
Hi Niklas,

To select the items in a list box based on the entry in a combo box you
can
use this:

Dim i
For i = 0 To YourList.ListCount
If YourList.ItemData(i) = YourComboBox Then
YourList.Selected(i) = True
End If
Next i

HTH
Jason

:

Hi!

I have never used listboxes before (haven´t hade any reason untill
now).

I have a form <frmAddAttachmentsToEmailMsg> in which I have one
combobox
<cboSearchFileName> and one listbox <lstSelectFileName>. In the
listbox
AfterUpdate_Event I have following code:

'==================================
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[DocumentID] = " & Str(Nz(Me![lstSelectFileName],
0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
'==================================

When I mark a record in the listbox the record is highlighted, which
is
exactly what I want.

Now to my problem:
I use the combobox to search for records which I then want to be
highlited
(selected) in the listbox. When I select a record in the combobox the
form
is uppdated with the record that I have searched for. BUT the record
is
NOT
highlighted in the listbox, which I want it to be. Since it´s much
easyer
to
see which record that have been selected.

I have following code in the combobox AfterUpdate_Event
'=======================================
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[DocumentID] = " & Str(Nz(Me![cboSearchFileName],
0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Me.lstSelectFileName.SetFocus
Me.cboSearchFileName = ""
'========================================

If there is abetter way of doing this then to use a combobox please
let
me
know.

One way could be to use a texbox where the user types in the name of
the
record that they want to be highlighted in the listbox and that the
listbox
highlight the record that match the textbox on the fly. But this may
not
be
a good idéa. And I surtanly doesn´t know how to implement it.

TIA!
// Niklas
 

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

Similar Threads

Textbox Filter 4
Error 2237 8
RunTime Error 3070 8
OnLoad event criteria 4
New record added to listbox, but won't load rec in form when selec 4
Error 2147352567 2
Search combo box 2
bookmark Problem 2

Top