Current Recordset does not support bookmarks - sql

I have this ASP classic code that will return a set of records (recordset):
adoRs.Open "EXEC SP_SelectFromTable", adocn, 1
Its obviously from a Stored Procedure source. Now I use a AbsolutePage property for pagination function but it cause an error:
Error Type: ADODB.Recordset (0x800A0CB3) Current Recordset does not
support bookmarks. This may be a limitation of the provider or of the
selected cursortype.
But when I changed it to a simple select statement like below. It work just fine.
adoRs.Open "SELECT * FROM tblSample", adocn, 1
Any concept I'm missing?

When I first started working with ADO in ASP I ad the same problem. Most of the easy to find documentation mentions setting the cursor type of the recordset object. But on our servers, I actually have to set it on my connection object to get it to work (never really figured out why).
So on my applications I set it on my connection object like this:
adocn.CursorLocation = adUseClient
Then I can set my recordset as:
adoRs.CursorType = adOpenStatic

Once the recordset is opened the datatype of Bookmark will be changed to either Double or Integer according to the recordcount. Just assign the record number in the variable of that type then it will work fine...
Note:-To know type of bookmark use typename(rs.bookmark) after recordset is opened

Related

Applying Filter on a disconnected ADODB Recordset in VBA

I 've got a disconnected recordset which can be copied to an Excel worksheet by method "CopyFromRecordset".
But before that I need to set a Filter on the recordset by Filter property:
Rst.Filter = "UnitPrice >100"
Rst.MoveFirst
Sheet1.Range("A2").CopyFromRecordset Rst
The code raises a run-time error of some Automation Error at "Rst.Filter..." line.
Is there something that I did wrong?! or simply we cannot apply filter to a disconnected recordset??!
After a lot of testing and searching, I could find the source of problem.
It was due to definition of data-type of fields appeneded to the recordset at the recordset creation time, which were all of type adVariant = 12 for ease.
Seems that this data type is no longer fully supported, and for filtering recordset, all data types of fields must be precisely defined at the creation and used properly in Filter string. see the link below:
https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/datatypeenum?view=sql-server-ver15

What is vba code to use filtered form results as recordset for a query

What is vba code to use filtered form results as recordset for a query?
I started first to see if I could create and then open a recordset…
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
CurrentDb.OpenRecordset ("rst")
And got the Run-time error ‘3078’ The MS Access database engine cannot find the input table or query ‘rst’ I haven’t worked with recordsets before. Thank you
Actually all you need is this
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
The recordset clone is already opened, and already exists.
So, you don't need the OpenRecordset command at all. This out of the box "handy" RecordsetClone exists for all forms, and you don't even have to open it.
Now that recordset will have the filtered data. It really then becomes a question as to what you want to do with the data.
However, say you had a report based on the same table as the form, the form becomes filtered?
Well, you actually in that case don't need (nor want) a reocrdset, but to simply open up that form with the current/same forms filter.
You can thus do this:
DoCmd.OpenReport "rptCustomers", , , Me.Filter
But, if you for some reason need/want to process a recordset based on the current filter? Then using RecordsetClone will work. And this is NOT to be confused with RecordSet.Clone (which also exits).
And as noted, it is already open and exists. So you only need this:
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone

Using the Month function as criteria in an Access SQL query

I'm trying to extract data from an Access 2016 database using SQL and VBA. Below is the code I'm trying to use and every time I run it, I get a "No value given for one or more parameters". I've also shown what I see in the immediate window.
vsql = "SELECT [ResDate],[ResNanme],[ResStart],[ResEnd] FROM [TrainingRoom] where Month([ResDate]) = " & MonNo
Set RecSet1 = Connection.Execute(vsql, dbrows, adCmdText)
Immediate Window:
SELECT [ResDate],[ResNanme],[ResStart],[ResEnd] FROM [TrainingRoom] where(Month([ResDate])) = 11
I don't see anything wrong but I'm sure this is user error. The "MonNo" variable is declared as an integer.
Any suggestions would be greatly appreciated. Thanks for the help.....
I've never used Execute method to open ADO recordset, only Open.
Assuming Connection is a declared and set variable - but it is a reserved word and really should not use as a variable. If code is behind same db pulling data from, could just use CurrentDb with DAO recordset variable and OpenRecordset method. Example that accepts default parameters for optional arguments:
Dim RecSet1 As DAO.Recordset
Set RecSet1 = CurrentDb.OpenRecordset(vsql)

Recordset.FindFirst method: why DOES it work with some of my Table-type recordsets?

I was trying to use the Recordset.FindFirst method with DAO recordsets, in Access VBA, when I came across the error:
Error 3251: "Operation is not supported for this type of object."
After some brief investigation on the MSDN, I discovered that the method only works on dynaset-type or snapshot-type recordsets. I changed my code from this:
Set rs2 = db.OpenRecordset("table_name")
rs2.FindFirst [search criteria]
to this:
Set rs2 = db.OpenRecordset("table_name", dbOpenDynaset)
rs2.FindFirst [search criteria]
and all was working fine.
However, I have another database where I have been using FindFirst on table-type recordsets without error.
Set rs = db.OpenRecordset("tblUsers")
rs.FindFirst [search criteria]
My questions are
Why this works in one database and not another, and
If it would be advisable to change the code to use dbOpenDynaset type recordsets instead?
When you OpenRecordset() on a query or attached table, Access defaults to a Dynaset type (dbOpenDynaset).
When you OpenRecordset() on a local table, it defaults to a Table type (dbOpenTable.)

Classic ASP, ADO, recordset not populating from Stored Procedure

In a Classic ASP script, I have a sql statement that executes a stored procedure:
sql="exec my_stored_proc"
I then attempt to fill an ADO Recordset object with the results and loop through the recordset.
The stored procedure itself is populating a virtual table and the last line of the procedure returns the results:
select tableName, subTable, FieldLabel, total, FieldOrder from #AdmissionsTable
When executed directly from SQL management studio, I get results, but when executed from the ASP page, this line:
do while not rs.eof
results in the error "Operation is not allowed when the object is closed."
I know it's not because I'm trying to execute a stored proc, because I tested it against another stored proc, and was able to get results into the rs object.
Is it because I'm using a virtual table? Or something else?
Extra code:
After the sql string is assigned I open the connection, set the rs object, and execute the query:
conn.Open strConnection
Set rs = server.createobject("ADODB.Recordset")
rs.open sql, conn
Then comes the error line:
do while not rs.eof
Further update:
Right after the rs.open line, I added some debug code to response.write "RS Populated," and this line executes. But then the error still appears directly after that, so I'm guessing this means that somehow the RS is getting closed right away. Not sure why.
Still further update:
I've at least isolated the problem. The err object returns "Query timeout" as the error, and rs.ActiveConnection.CommandTimeout returns "30" as my timeout value.
The query is large and takes at least 60 seconds to run, so I tried setting rs.ActiveConnection.CommandTimeout = 120, but it still fails and - most maddeningly - it still returns "30" as the timeout value.
If rs.ActiveConnection.CommandTimeout = 120 didn't work to increase the timeout, how can I get that value up?
Problem solved. I had to set the CommandTimeout property at the connection level:
conn.CommandTimeout=120
Now it works.