Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / June 2007

Tip: Looking for answers? Try searching our database.

Double clik item on list box to auto populate other controls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sara - 20 Jun 2007 21:05 GMT
Hi everyone

I am working on a form that has a list box control of items, the
functionality that I need to add is that when the user double cliks on one
item of the list box the other controls that I have on my form should
autopopulate.
This listbox has InquiryId's which are the primary key of my table inquiries.
I am fairly new coding but so far this is what I've tried:

P.S.: "ViewInquiries" is the name of my listbox on the form, and the  
"AccessNSUnionInquiries" that I am using on the Select Stament is a query.

Private Sub ViewInquiries_DblClick(Cancel As Integer)

Dim rs       As Recordset
Dim strSQL    As String
Dim db              As DAO.Database
Dim sArgs          As String

For Each row In Me.ViewInquiries.ItemsSelected
       sArgs = Me.ViewInquiries.Column(1, row)
       Next row

sArgs = "Form=" & Me.Name & ";" & _
           "InquiryID=" & sArgs & ";"
           
Set db = CurrentDb
strSQL = "SELECT * FROM AccessNSUnionInquiries" & _
"WHERE Inquiries.InquiryID = sArgs;"

Set rs = CurrentDb.OpenRecordset(strSQL)

            With rs
           
               Me.accessNSID = .Fields("RacfID")
               Me.FirstName = .Fields("FirstName")
               Me.LastName = .Fields("LastName")
               Me.Email = .Fields("Email")
               Me.Company = .Fields("Company")
               Me.City = .Fields("City")
               Me.State = .Fields("State")
               Me.ProblemName = .Fields("ProblemCategory")
               Me.ProblemDescription = .Fields("ProblemType")
               Me.Terminal = .Fields("Terminal")
               Me.Train = .Fields("TrainNo")
               Me.Day = .Fields("Day")
               Me.Unit = .Fields("Unit")
               Me.Comments = .Fields("Comments")
               Me.Frame = .Fields("Source")
             End With
rs.Close
  Set rs = Nothing
  Me.Requery
   db.Close
 Set db = Nothing
 
End Sub

I don't even know if this code is close to being correct, I will provide
more details if needed, I would greatly appreciate any help!
Carl Rapson - 20 Jun 2007 23:01 GMT
> Hi everyone
>
[quoted text clipped - 57 lines]
> I don't even know if this code is close to being correct, I will provide
> more details if needed, I would greatly appreciate any help!

You don't say what problem you're having. It appears that you only want to
process a single item from the listbox, so why do you have it set for
multiselect? You could change the Multiselect property to None and do the
following in the DblClick event:

strSQL = "SELECT * FROM AccessNSUnionInquiries" & _
               "WHERE Inquiries.InquiryID = " & Me.ViewInquiries
Set rs = CurrentDb.OpenRecordset(strSQL)
' Populate your fields like you do now...

Carl Rapson
Sara - 20 Jun 2007 23:29 GMT
The problem is that  the code doesn't work,  when I double clcik an item from
the list box it automatically switchs to the visual basic code.
I use basically one item from the list (InquiryID) which is  primary key to
the table from where I am retrieving all the information related to that ID.
I m sorry If I am not very clear, it is kind of a complex case for me a
beginner.

> > Hi everyone
> >
[quoted text clipped - 69 lines]
>
> Carl Rapson
Carl Rapson - 21 Jun 2007 16:00 GMT
What do you mean, "switches to the visual basic code"? Do you mean the VBA
code window opens? If so, is a particular line of code highlighted? Does an
error message appear?

You might want to try my suggestion and see if it makes a difference. Just
replace everything from your

   For each row...

line through (and including)

   strSQL = "SELECT..."

with the code I posted, and see what happens. Note: you also don't need the

   Set db = CurrentDb

and

   db.Close
   Set db = Nothing

lines, because you're not using the 'db' variable.

Carl Rapson

> The problem is that  the code doesn't work,  when I double clcik an item
> from
[quoted text clipped - 83 lines]
>>
>> Carl Rapson
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.