ListBox/Recordsets

databases United Kingdom
  • 19 years ago

    Ok, a little help would be greatly appreciated... Here's a simplified version of the scenario:
    I've got a field (Text Box) on my form, and it's connected to a Data Control, which in turn is connected to a table in MS Access. In my MS Access table I have 3 records. I've placed these 3 records inside the textbox, which of course I can scroll through with the Data Control, as they appear in the text box. Now I also have a ListBox on my form. Inside this ListBox I programatically placed ONE of the 3 records that are in the text box. So the Text Box contains 3 records which you scroll through, and the ListBox contains 1 of those 3 records. Now here's the problem. I want to be able to click (or double click) on this single record in the ListBox, and when I do, I want that record to appear in the Text Box, as the Text Box will have a different record from the ListBox. So I'm stumped, it's not as easy as it sounds. So as a recap... I want whatever record in the ListBox when clicked, to appear in the Text Box.


    Well I tried explaining the situation as best as possible.
    I would appreciate anyone's help.

  • 19 years ago

    Could you show me the code you use to programatically load one of the records into this textbox? You might just alter that code to make a separate sub of it, just like:


    Public Sub LoadRecordsIntoTextbox(varRecordNumber as Long)
       ........
    End Sub


    And then in the OnClick property of your listbox do something like:


    Private Sub Listbox_Click
       LoadRecordsIntoTextbox(Listbox.Value)
    End Sub


    That's supposed to work... If you have any trouble just put the code here and I'll see what I can do...


    Regards,


    Thamar

  • 19 years ago

    Well, here's the code which I use to insert the current record in the textbox into the listbox. I'm not sure if it'll help you help me, as it's probably difficult without the rest of the program, which is almost 3000 lines of code so it would be kind of difficult to paste it in here...
    Basically, I allow the user to search for any record, and when a record is found, it displays the name of that record in the listbox, then say the user freely moves about the records in the textbox using the Data Control. Now the user wants to go back to that record that was found earlier and placed in the listbox. So he clicks that record in the listbox, which SHOULD bring that record back up in the textbox. Maybe that's a better explanation, I don't know.
    If you can't provide extra help, that's ok, and thanks.



                   .datPersonal.Recordset.FindFirst "fldLastName = " & "'" & txtFind.Text & "'"


                   If (.datPersonal.Recordset.NoMatch = True) Then
                       MsgBox "Found no instances of " & txtFind.Text, vbInformation, "Find"
                   Else
                       .lstPersonal.AddItem (.txtLastNameP.Text & ", " & .txtFirstNameP.Text)
                       Do Until .datPersonal.Recordset.EOF
                           .datPersonal.Recordset.FindNext "fldLastName = " & "'" & txtFind.Text & "'"
                           ' If no match exists, inform the user
                           If (.datPersonal.Recordset.NoMatch = True) Then
                               If (.lstPersonal.ListCount > 1) Then
                                   MsgBox "Found " & .lstPersonal.ListCount & " instances of " & txtFind.Text, vbInformation, "Find"
                               Else
                                   MsgBox "Found " & .lstPersonal.ListCount & " instance of " & txtFind.Text, vbInformation, "Find"
                               End If
                               Exit Do
                           Else
                               .lstPersonal.AddItem (.txtLastNameP.Text & ", " & .txtFirstNameP.Text)
                           End If
                       Loop
                   End If


Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.” - Alan Kay