Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Access Select Multiple Records on List and Transfer to Subform

Posted on 2009-05-12
9
343 Views
Last Modified: 2013-11-28
Greetings:

I have a main form (unbound)  that contains a list that is generated from several search fields.  Currently, I can click on the record, and press a command button that will copy that record information over to a bounded subform.  Works great!  However, looks like we would like to be able to select multiple record on the list and have those records be copied over to the subform for browsing.

Here is the code in the list table review subform(frmBrowseByName_Single):
Private Sub Command83_Click()
DoCmd.OpenForm "frmBrowseByName_Single", , , "[StructureID]=" & Me.lstStructures
On Error GoTo Err_Command83_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmBrowseByName_Single"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command83_Click:
    Exit Sub

Err_Command83_Click:
    MsgBox Err.Description
    Resume Exit_Command83_Click
   
End Sub

Here is the code in the subform (frmBrowseByName_Single):
Private Sub Form_Load()
'Used to allow for next record to be browsed
Dim rstFormRecords As Object
Dim lngStructureID As Long
   
    lngStructureID = Me.StructureID
    Me.FilterOn = False
   
    Set rstFormRecords = Me.Recordset.Clone
    rstFormRecords.FindFirst "[StructureID] = " & lngStructureID
    If Not rstFormRecords.EOF Then Me.Bookmark = rstFormRecords.Bookmark

End Sub

If I set the multiple select to extended, and the code stopped at the StructureID =.  

Thanks for the help!!

heather
0
Comment
Question by:Heather_D
  • 5
  • 4
9 Comments
 
LVL 5

Expert Comment

by:josephwalsh
ID: 24367007
Take the query that generates the list.
That is also the basis of your recordsource for the other form.

Therefore create your new query as follows (set this as the recordsource for the other form):
SELECT * FROM yourtablename/queryname
WHERE [StructureID] IN yourexisting searchquery
0
 

Author Comment

by:Heather_D
ID: 24407424
Hi Joseph,

Not sure I understand.  Here is my search query:

SELECT tblNCHPOsurvey.StructureID, LTrim([PropertyFirstName] & " " & [PropertyName] & " " & [PropertyTown]) AS NameandType, tblNCHPOsurvey.COUNTY, LTrim([LocationPrefix] & " " & [PropertyLocation] & " - " & [PropertyTown]) AS AddressTown, tblNCHPOsurvey.SSN, tblNCHPOsurvey.PropertyName, tblNCHPOsurvey.PropertyFirstName, tblNCHPOsurvey.PropertyTown, tblNCHPOsurvey.NRCODE, tblNCHPOsurvey.LocationPrefix, tblNCHPOsurvey.PropertyLocation, tblNCHPOsurvey.PropertyTown, tblNCHPOsurvey.Style, tblNCHPOsurvey.Material, tblNCHPOsurvey.Construction, tblNCHPOsurvey.Comment, tblNCHPOsurvey.Date, tblNCHPOsurvey.ListStatus
FROM tblNCHPOsurvey
WHERE (((LTrim([PropertyFirstName] & " " & [PropertyName] & " " & [PropertyTown])) Like "*" & [forms]![frmSearch]![txtNameandType] & "*") AND ((tblNCHPOsurvey.COUNTY) Like "*" & [forms]![frmSearch]![cmbCounty] & "*") AND ((LTrim([LocationPrefix] & " " & [PropertyLocation] & " - " & [PropertyTown])) Like "*" & [forms]![frmSearch]![txtPropertyLocation] & "*") AND ((tblNCHPOsurvey.PropertyTown) Like "*" & [forms]![frmSearch]![txtTown] & "*") AND ((tblNCHPOsurvey.NRCODE) Like "*" & [forms]![frmSearch]![txtNRCode] & "*") AND ((tblNCHPOsurvey.Style) Like "*" & [forms]![frmSearch]![txtStyle] & "*") AND ((tblNCHPOsurvey.Material) Like "*" & [forms]![frmSearch]![txtMaterial] & "*") AND ((tblNCHPOsurvey.Construction) Like "*" & [forms]![frmSearch]![txtConstruction] & "*") AND ((tblNCHPOsurvey.Comment) Like "*" & [forms]![frmSearch]![txtComment] & "*") AND ((tblNCHPOsurvey.Date) Between Nz([Forms]![frmSearch]![txtEarlyDate],[Date]) And Nz([Forms]![frmSearch]![txtLateDate],[Date])) AND ((tblNCHPOsurvey.ListStatus) Like "*" & [forms]![frmSearch]![cmbListStatus] & "*"))
ORDER BY tblNCHPOsurvey.COUNTY, tblNCHPOsurvey.PropertyName, tblNCHPOsurvey.PropertyFirstName, tblNCHPOsurvey.PropertyTown;

THanks,

Heather
0
 

Author Comment

by:Heather_D
ID: 24422927
Do you need a copy of the database?  

Any suggestions would be greatly appreciated!

Thanks,

Heather
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:Heather_D
ID: 24423169
DoCmd.OpenForm "frmBrowseByName_Single", , , "[StructureID]=" & Me.lstStructures

If I change the list select to extended, I get an error in the above code.  Looks like it might have something to do with the structureid being = to something instead of multiple things.
0
 
LVL 5

Expert Comment

by:josephwalsh
ID: 24424199
A copy of the datbase would helpful.
Thanks
Joe
0
 

Author Comment

by:Heather_D
ID: 24424267
This is the database.  Go to switchboard form and click on search/browse by Name.  The search Name form (frmsearch)  is my original form and then when you click look record, that form is the subform(frmbrowsebyname_single).

expert-exchange.zip
0
 
LVL 5

Expert Comment

by:josephwalsh
ID: 24429774
Thanks
0
 
LVL 5

Accepted Solution

by:
josephwalsh earned 500 total points
ID: 24429811
I have attached an updated database.
JPW has been put in a comment where changes have been made.

I made changes to the search form.
The listbox has been changed to allow multiple select.
There is new code in 'View a Record' where it builds the filter for the subform.
Option explicit has been added to give more control over variable defs etc.

I made a few small changes to frmBrowseByName_Single to allow the filter to work correctly.

Regards,
Joe
expert-exchangenew.zip
0
 

Author Closing Comment

by:Heather_D
ID: 31580587
Super!! I love you!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

840 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