Solved

vb6 List Box Double-Click Problem

Posted on 2014-01-03
4
392 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 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 500 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 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now