Hi, I want my Form to use data in a Recordset. Can I pass a recordset to a Form ?
Or - should I just send the sql in as OpenArgs? Only I've got the recordset already open and only want the Form if record count > 1
Hi, I want my Form to use data in a Recordset. Can I pass a recordset to a Form ?
Or - should I just send the sql in as OpenArgs? Only I've got the recordset already open and only want the Form if record count > 1
There are plenty of ways to get a recordset into a form.
You can’t pass a recordset directly through OpenArgs since it only accepts strings. However, you can send an SQL query string with OpenArgs and use it to open a recordset in the form. Alternatively, you can pass a JSON string with multiple records through OpenArgs. Your form could also access a recordset from another open form or use a public variable to store and access the recordset.
Please click on the ⭐ below if this post helped you.
↓
Cart before the horse.
What are you trying to accomplish? If you want to open the form to show only a single record, set filters in the Open command. Recordsets are not required to do it.
In the form's Open event you set its recordset to the open recordset:
https://github.com/MicrosoftDocs/VBA...m.Recordset.mdCode:Me.Recordset=rsYourRecordset
https://www.access-programmers.co.uk...dsource.56221/
Cheers,
The form has a listview control showing many records, not just one.
But if there are no records to show no form is necessary. The recordset is establish to get a count... my question was how best to pass it to the Form. Didn't seem right to open it a second time but that's what i ended up doing.
Edgar had the answer, a public variable, but by then I'd used sql/Open Args.
Gicu, here's the click event
Where would you put your Open event?Code:Private Sub cmdShowHits_Click() sql = "Select Distinct Path, tPerformer, Media from Tracks Where tCat = " & ThisDisk() & " and Media = '45';" Set r = CurrentDb.OpenRecordset(sql) If r.RecordCount > 0 Then DoCmd.OpenForm "frmListview2", acNormal, , , , , sql Else MsgBox "Nothing Found" End If End Sub
You don't need to open a recordset to get the count:
What I showed you was supposed to go into the frmListview2 Open event, not in the calling form. You would need to use a public variable to be able to pass the recordset, but it might not be needed. I have seen your posts in the past about using listview controls instead of the built-in listboxes and I do not have experience with listviews, but wouldn't the recordset you're asking about need to be bound to the ListView control and not the actual form?Code:if dCount("*","Tracks","tCat = '" & ThisDisk() & "' and Media = '45'")>0 Then 'Assumes tCat is a string
Cheers,