Solved

return records from double click in listbox

Posted on 2008-06-25
1
276 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

758 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

21 Experts available now in Live!

Get 1:1 Help Now