Print highlighted rows from subform? (1 Viewer)

damageinc86

Registered User.
Local time
Yesterday, 20:30
Joined
Dec 18, 2016
Messages
24
I have a Form with a subform in it that has a query as a source, and updates the query to filter by whatever is typed in a search txtbox. It requeries when you click the search button based on what's in the search txtbox. Now I'm just trying to figure out how to let the user highlight a few rows, and then print only those rows from the subform. Been trying all day with trying to feed something to a report but it always print preview's all records from the subform query, not the selected ones.
 

Minty

AWF VIP
Local time
Today, 04:30
Joined
Jul 26, 2013
Messages
10,387
Do a search on here for "selected records" someone came up with a method of doing this. Alternatively if you can list you form items into a multi-select list box this becomes a lot easier.
 

damageinc86

Registered User.
Local time
Yesterday, 20:30
Joined
Dec 18, 2016
Messages
24
Yes, I've seen the listbox suggestion all over, but when I try to put a listbox in my form I can't figure out how populate the list box with my query results. So I don't even get past step one. I just want to be able to highlight the records and print them only. Either that or figure out how to make a checkbox field the ONLY field in my table that the user can edit. i was able to print the report of the query using selected checkbox macro, but then that made my records all editable, which is not good.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:30
Joined
Aug 30, 2003
Messages
36,140
Can't you make the row source of the listbox your query? Any subform solution I've seen involves a field in the table or a temp table with the extra field. The listbox is much easier.
 

damageinc86

Registered User.
Local time
Yesterday, 20:30
Joined
Dec 18, 2016
Messages
24
Yes the listbox row source only shows the first field, my ID field. so it's just a number. Anyone who could take the database and show me the code in practice then send it back? Or maybe explain how to make the checkbox field the only field in the record that can be edited. That would work just as well I suppose for now. But Ideally it would be best if a user could just select the rows (records) from the subform and then click a print preview button that will send only those selected records to the query so that the report on the query prints out just those records. But I saw some OnTimer stuff that you have to do since when you click it takes focus away from the subform, but I have no idea how to make other's complicated code work in my instance. It just breaks my form.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:30
Joined
Aug 30, 2003
Messages
36,140
Sounds like you need to adjust the column count and column widths properties. You can attach the db here if you're still stuck after doing that.
 

damageinc86

Registered User.
Local time
Yesterday, 20:30
Joined
Dec 18, 2016
Messages
24
Yeah, now after trying so many different things, somehow I managed to break by text box for the search, can't even type anything into it again, even when I deleted it and re-created it. I'm at a complete loss now. I never would've guessed it would be this hard to just select some records and print them.

Looks like I created a backup when I was trying out using a yes/no checkbox field in the table, but couldn't select it in my subform query because I want the records locked so no one can edit the data. So I'm attaching that one.
 

Attachments

  • ODL template_Backup.accdb
    568 KB · Views: 72

JHB

Have been here a while
Local time
Today, 05:30
Joined
Jun 17, 2012
Messages
7,732
You don't have a real subform, but only a query placed in the form, and therefore you don't have the events required to perform the ability you want.
Adjusted database attached.
 

Attachments

  • ODL template_Backup.accdb
    604 KB · Views: 74

damageinc86

Registered User.
Local time
Yesterday, 20:30
Joined
Dec 18, 2016
Messages
24
Hey thanks, but the print still shows both records even though i select only one. And I accidentally clicked a checkbox for a new record and it had some crazy error messages and a debug thing pop up.
 

JHB

Have been here a while
Local time
Today, 05:30
Joined
Jun 17, 2012
Messages
7,732
Hey thanks, but the print still shows both records even though i select only one. And I accidentally clicked a checkbox for a new record and it had some crazy error messages and a debug thing pop up.
Yes because I thought you only had a problem how to set the "Select" control to "Yes/No", and were able to fix the other things yourself.
But here is a new Adjusted database attached.
 

Attachments

  • ODL template_Backup.accdb
    596 KB · Views: 70

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:30
Joined
Feb 28, 2001
Messages
27,512
Just a note: I've had some success using list boxes and combo boxes, but here is the thing to know about them. Unless something has recently changed, these two controls have different quiescent behavior.

A list box can be told to show you multiple columns statically. It stays fixed in size on the form and you have to do some sort of For-loop to visit every record in the list to test for the .Selected property as T/F.

A combo box will only show you a single selected value statically. When you click on the little down-arrow / triangle icon at the right, the box can expand to show multiple columns, but when you are done with it, it shrinks back down to text box size. At that point that a selection is made, the .Value of the combo box is the value associated with the bound column of the selected record.

To change the contents of either, what I usually did was to have "SELECT {set of fields} FROM {table/query name} WHERE " in a predefined string that was consistent with the setup of the combo or list. Then when I did something to change selection criteria, I rebuilt a string listing my criteria in a second string. After that, I would do something like:

Code:
box.RecordSource =  SelectString & WhereString
box.Requery

As long as I didn't screw the pooch with the dynamic WhereString, this worked like a champ. And trust me, it won't take long for you to get this right - because you will get errors on the Requery step until you do.
 

damageinc86

Registered User.
Local time
Yesterday, 20:30
Joined
Dec 18, 2016
Messages
24
Yes because I thought you only had a problem how to set the "Select" control to "Yes/No", and were able to fix the other things yourself.
But here is a new Adjusted database attached.

Awesome that works pretty well! Could you explain what you did there? What changed? Is there a way to clear the select checks with a button perhaps? I noticed when I search again, whatever I had checked last time will already be selected.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:30
Joined
Feb 28, 2001
Messages
27,512
The way to deselect selections in a list box is to (a) reload the .RowSource and then do a .Requery on it or (b) in a For loop over (I think) 0 to .Items.Count -1, you can do a .Selected(loop-index) = False.
 

damageinc86

Registered User.
Local time
Yesterday, 20:30
Joined
Dec 18, 2016
Messages
24
Yeah, I got a button to de-select whatever boxes where checked, found some simple code on some other post that works great. But for my Select all button, I can't get it to give the focus back to the checkbox field within the query once it has been clicked. So It only populates all the checkmarks once I hover the mouse over the checkbox field, or click just outside of the subform border. I couldn't intuitively find any code out myself, or find a macro to select that field again to reflect the changes that the Select all button made. That is the final little piece i'd like to have just in case someone wants to select all/almost all of the records.
 

JHB

Have been here a while
Local time
Today, 05:30
Joined
Jun 17, 2012
Messages
7,732
..I noticed when I search again, whatever I had checked last time will already be selected.
Yes it will be selected because you've the "Select" field in your table.
New version of the database attached.
 

Attachments

  • ODL template_BackupNew.accdb
    616 KB · Views: 84

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:30
Joined
Aug 30, 2003
Messages
36,140
I'll point out that the subform method using a field in the table can be problematic in a multi-user environment. If two people are trying to run this at the same time, they will overwrite each other's selections.
 

JHB

Have been here a while
Local time
Today, 05:30
Joined
Jun 17, 2012
Messages
7,732
I'll point out that the subform method using a field in the table can be problematic in a multi-user environment. If two people are trying to run this at the same time, they will overwrite each other's selections.
Surely I do agree.
 

damageinc86

Registered User.
Local time
Yesterday, 20:30
Joined
Dec 18, 2016
Messages
24
Thankfully this will be one user at a time on one computer. But I would still be curious how to do the same thing in a multi-user environment.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:30
Joined
Aug 30, 2003
Messages
36,140
The listbox would work very nicely in a multi-user environment. Failing that, you're looking at a temp table or some such thing.
 

Users who are viewing this thread

Top Bottom