Solved

Access Select Multiple Records on List and Transfer to Subform

Posted on 2009-05-12
9
339 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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…

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

19 Experts available now in Live!

Get 1:1 Help Now