Solved

return records from double click in listbox

Posted on 2008-06-25
1
277 Views
Last Modified: 2013-11-28
Hi,

I have form which has a list box on which lists all customers in the tbl_contacts table.  What i'm trying to do is allow a user to double click one of the customers in the lb and have all the data from tbl_contacts populate into the appropriate fields on the form or that customer.

The form has unbound text boxes on setup to accept data from tbl_contacts.

Hope someone can shed some light.

Regards,
Tom
0
Comment
Question by:d10u4v
1 Comment
 
LVL 58

Accepted Solution

by:
harfang earned 500 total points
ID: 21871142
The easiest would be to use a bound form with bound controls and use the control wizard to create a combo box to "find a record on this form". The code will work the same way with a list box (change the combo to a list box after the wizard has run).

If you prefer, the snippet below shows one way to do it, provided that the list box returns the ID field of tbl_contacts.

(°v°)

Private Sub lstContacts _DblClick(Cancel As Integer)

    

    Dim strSQL As String

    

On Error Goto Problem

    

    strSQL = "Select * From tbl_contacts Where ID=" & lstContacts

    With CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)

        Me.txtContactName = !ContactName

        Me.txtETC = !ETC

    End With

    Exit Sub

    

Problem:

    Me.txtContactName = Null

    Me.txtETC = Null

    MsgBox Err.Description

    

End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

919 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

16 Experts available now in Live!

Get 1:1 Help Now