Improve company productivity with a Business Account.Sign Up

x
?
Solved

vb6 List Box Double-Click Problem

Posted on 2014-01-03
4
Medium Priority
?
421 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
  • 2
  • 2
4 Comments
 
LVL 77

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 77

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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

606 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