?
Solved

vb6 List Box Double-Click Problem

Posted on 2014-01-03
4
Medium Priority
?
412 Views
Last Modified: 2014-01-03
Here is a problem for the old sages...I have a vb6 app that I am upgrading.  It has a list box with a list of data of varying number.  It is basically a list of participants in a race with their first name, last name, gender, etc.  What I want to do is be able to double-click on that list and have the data edit form come up as a modal form with that person's data populating the fields on that form.

Currently you have to open the edit form, find their unique ID in a drop down and click on that to get their data to populate.  I want to make the process quicker and easier.

Thanks a ton.  Best site ever for helping hacks like me...
0
Comment
Question by:Bob Schneider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 2000 total points
ID: 39753919
It's not clear what your exact situation is, if you are using a database, whether any database is accessed using ADO or DAO, and whether the controls are bound or not.

Here is some very simple code that used an arbitrary function to populate one of two text boxes on the called Form

Option Explicit

Private Sub Form_Load()
List1.AddItem "One"
List1.AddItem "Two"
List1.AddItem "Three"
List1.AddItem "Four"
List1.AddItem "Five"

End Sub

Private Sub List1_DblClick()
Form2.Text1.Text = List1.Text
Form2.Show vbModal
End Sub

Open in new window


Option Explicit

Private Sub Form_Activate()
    Text2.Text = GetField2(Text1.Text)
End Sub

Function GetField2(strText As String) As String
    GetField2 = strText & "2"
End Function

Open in new window

0
 

Author Comment

by:Bob Schneider
ID: 39753931
Yes I am using sql server 2008 but the only things I am not clear on is:

1) How to get the frmEditData to open when double clicking an item in the list of the frmPartic form, and

2) How to pass the unique id of the record that was selected via double-click on the frmPartic form to the frmEditData form so that it can populate the necessary fields.

Sorry I was not more complete initially.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 39754036
The sample code above shows how to open the second form with a double-click.

You can get the value by

a) In Form2 you can read it from Form1:
   Form1.List1.text

b) Set a variable of form2

Dim MyFieldValue  as string
 Private Sub List1_DblClick()
     Form2.MyFieldValue = List1.Text
    Form2.Show vbModal
End Sub

c) as in the original example, you can set the value of a Text box control

d) Use a global variable (not recommended)
0
 

Author Closing Comment

by:Bob Schneider
ID: 39754170
Awesome!  Thank you!
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 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