Solved

Access Select Multiple Records on List and Transfer to Subform

Posted on 2009-05-12
9
340 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
 

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

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