Full Version: Setting a form in datasheet view = a recordset
UtterAccess Forums > Microsoft® Access > Access Forms
I know I can make the recordset = an SQL statement.
However, can I make the datasheet display the contents of a recordset?
What I think your asking is whether or not you can make a form that is in datasheet view display a recordset. All you need to do is set the Recordsource to an SQL statement. I included an example below.
ormName.RecordSource = "SELECT * FROM TableName WHERE PrimaryKeyField = '<a primary key>'"
This should return just 1 recordset to display in the form. Make sure you set the form's Default View to Datasheet. Is this what you were looking for?
I got that to work, but my SQL query is rather complex and runs over many records and tables.
opened it once in a recordset (which I have to do for various reasons so I can work with it, get counts, etc).
So I want to open that form and use the recordset rstResults for the form to pull its data from, instead of having to run that query all over again.
Can I do that?
OR, if I can't do that: Can I open the form using SQL (which I can as you just demonstrated) and THEN do recordcounts on the form?
Oalso need to be able to iterate through the records on the form so I can add certain ones to tables, etc.
However, my fear is that if I COULD do that the user could stop the process by closing the form or other nasty things could happen so I wanted to do it behind the scenes with a recordset and use that same recordset over and over for various displays.
(I declared the recordset as Private so as I understand it that lets me use it anywhere in my code so that I can populate it once, then use it again and again).
When you refer to recordset, are you using DAO or ADO?
ADO for the recordset.
finally sorted out what I was doing wrong. I can now get a form to be a recordset.
I had some odd typos taking place but what I'm using is:
DoCmd.OpenForm "frmFormName", acFormDS, , , acFormreadOnly
Set Forms![frmFormName].RecordSet = rstResultsToDisplayInForm
and that seems to be working for me.
This lets me just run the query once, then open it in form views to play with or other things instead of having to run the query over and over again.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.