Listbox Double Click

JoseO

Registered User.
Local time
Today, 12:41
Joined
Jul 14, 2013
Messages
72
Hi there!

I've got a listbox (SelectedSongs) which lists selected songs that is fed by a table containing: My primary key (SongID) then a PrintOrder number and finally the title of the song in the third column.

Here's the code I have in the double click event:
Code:
Me.Recordset.FindFirst "SongID=" & Me.SelectedSongs

The code works but it is reading the number of songs contained in the listbox and going to said record. So, if I fill the listbox with, say, 5 songs and I double click the fifth songs, the above code assumes that the SongID is "5" not SongID 94 as it should for that specific selection.

I tried using a string variable to refer specifically to the song title but I failed.

Any suggestions? Thank you much!
 
You need to use, as the Bound Column of the Listbox, the column (in this case the columns start with 1, not 0) that holds the SongID.

Your attempt at using the song title failed, I suspect, because the syntax is different for a Text Field, as opposed to a Number Field. Syntax for Text would be:

"SongTitle='" & Me.SelectedSongs & '"'

Notice the position of the single quotes and the double quotes. Also note that, in this case, the Bound Column of the Listbox needs to be the column that holds the SongTitle.

Linq ;0)>
 
Thank you missinglinq for the quick reply - much appreciated.

I already tried pointing the code to column 1 but it returns an error: 3077 However, if I enter a zero then it returns the number of the song within the listbox (the PrintOrderID) and does not assume the "True" SongID per my "stickman" drawing below the code.

Code:
Private Sub SelectedSongs_DblClick(Cancel As Integer)
  Me.Recordset.FindFirst "SongID=" & Me.SelectedSongs.Column(1)
End Sub

Take the first song below "What we proclaim" it is song number one in the listbox but, in the table, it's song ID 221. But, when the double click event is executed, the forms sees it as SongID 1 and not 221 as it should be. So, the textbox that is supposed to display SongID 221 displays SongID 1.

(SelectedSongs listbox)
=========================================
| 1. What we proclaim
| 2. I am not the same
| 3. Here in my shame
| 4. Might be today
|=========================================
 
He's not saying to point the code at a certain column, he's saying that in the listbox's properties menu, the bound column should be the number of the column (starting at 1) which holds the SongID. If that's the first column, then Bound Column is 1, second would be 2, etc. You can find it in the Data tab in the control's properties.

It's in the properties for the control itself, not anything you do in code.

Error 3077 is 'Syntax error (missing operator) in expression'; it's a standard syntax error that can be addressed once you've properly set the Bound Column property.
 
Thank you Frothingslosh. I apologize. I got so focused on the code that I missed what missinglinq's instruction was.

The bound column was already set to 1- still got the same error; no go.
 
sounds like the rowsource for your listbox should contain 3 columns

SongID..SongNumber..SongName
221.......1..................What we proclaim
etc

the bound column should be 1
the column widths would be 0;1;5 (or just 0)
the column count would be 3

then this code

Me.Recordset.FindFirst "SongID=" & Me.SelectedSongs

will work
 
Out of curiosity, is SongID saved as text or number?
 
CJ_London,

SPOT ON!! The rowsource was the culprit. Shame on me for not opening the zoom box and checking things out there. Your prescription did the trick!

Frothingslosh, I had the field as a number. Thanks again to:


  1. missinglinq
  2. Frothingslosh
  3. CJ_London
I appreciate you guys and this wonderful site tons and tons!!
 

Users who are viewing this thread

Back
Top Bottom