Solved

Saving  selected data from list box as a variable

Posted on 2014-10-18
2
251 Views
Last Modified: 2014-10-18
I have successfully created a search text box to jump to a record in a list box.

Now I want to store the information from the selected record as variable data to be used in a series of form text boxes.

Here is the code I have so far:

Private Sub lstLeft_Click()
    Dim strName As String
    Dim strEmpID As String
    Dim intItem As Integer
   
    intItem = 0 To lstLeft.ListCount - 1
   
    If lstLeft.Selected(intItem) Then
           TempVars.Add "strName",lstLeft.Column(2, intItem) & ", " & lstLeft.Column(3, intItem)
           TempVars.Add "strEmpID", lstLeft.Column(1, intItem)
    End If
End Sub

The "intItem = 0 To lstLeft.ListCount - 1" is not correct.

I am only "clicking' on one record and then clicking a command button to navigate to the next form.

Thanks

Glen
0
Comment
Question by:GPSPOW
2 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 40388884
<<I am only "clicking' on one record and then clicking a command button to navigate to the next form.>>

  There's no need for the loop then.  The list control itself will contain the value of the bound column.  So you just want to do:

           TempVars.Add "strName",lstLeft.Column(2) & ", " & lstLeft.Column(3)
           TempVars.Add "strEmpID", lstLeft.Column(1)

and watch it; the column property is zero based.

Jim.
0
 

Author Closing Comment

by:GPSPOW
ID: 40388971
Thanks
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question