recordset

Excel VBA function with Recordset (Performance issue)

╄→尐↘猪︶ㄣ 提交于 2019-12-02 09:36:19
I have a database in SQL Server that I'm using to feed some financial reports in Excel. I'm using Recordsets through a custom Excel Function that uses arguments from Cells to build the SQL queries. Here is how the code looks: Public Function Test(arg1 As String, arg2 As String, arg3 As Integer, arg4 As Integer, arg5 As String) As Variant Dim oConnection As ADODB.Connection Set oConnection = New ADODB.Connection Dim oRecordset As ADODB.Recordset Set oRecordset = New ADODB.Recordset Dim strSQL As String strSQL = "SELECT SUM(BALANCE) as Total FROM Accounting WHERE ARGUMENT1 = " & Chr$(39) & arg1

Why should I close and destroy a recordset?

百般思念 提交于 2019-12-02 05:09:34
I read this article: http://www.utteraccess.com/wiki/Recordsets_for_Beginners , and it says that it's important for me to close and destroy RS's like this: rs.close Set rs = Nothing and if I don't, some bugs may happen. What kind of bugs? What does rs.close means? Does it mean that the connection to the database is kept open for as long as the rs isn't closed? rs.close cleans up the resources that are used internally, however because ASP is a single process that doesn't have any GC the Set rs = Nothing aids in the clean up. It de-references your objects, without it you'll have a memory leak.

ADO Recordset Not Staying Open in VBA - “Operation is not allowed when the object is closed”

六月ゝ 毕业季﹏ 提交于 2019-12-01 22:11:06
I don't really understand what has happened here. I'm using Excel VBA to connect to a SQL Server Express database and return an ADO Recordset. I had it working initially, but my code was a bit messy so I created a new module and copied the code across, tidying it up as I went along. Now, when I try to run the Sub just to return a the recordcount, I get the error "The operation is not allowed when the object is closed." The code breaks on the MsgBox line. Here is the simplified code: Dim Server As String Server = "ServerName" Dim Database As String Database = "DatabaseName" Dim UserID As String

WHERE IN Query with two recordsets in Access VBA

你离开我真会死。 提交于 2019-12-01 14:37:24
My first post here, so i hope this is the right area. I am currently trying to compare 2 recordsets, one of which has come from an Excel named range, and the other from a table in the Access database. The code for each is: Set existingUserIDs = db.OpenRecordset("SELECT Username FROM UserData") Set IDsToImport = exceldb.OpenRecordset("SELECT Username FROM Named_Range") The problem is that I would like to somehow compare these two recordsets, without looping (there is a very large number of records). Is there any way to do a join or similar on these recordsets? I can not do a join before

Problems with Recordset Filter

白昼怎懂夜的黑 提交于 2019-12-01 14:27:48
I'm having trouble with a filter on an ADO Recordset in legacy ASP Classic code, and I'm trying to understand if what I'm trying to do is not supported, or if I'm just doing it wrong. I have a recordset of Items, and they have a Status of 1 (active) or 0 (inactive), and an optional End_Date. In my administrative user interface, I have a control to show all items or only those that should be displayed to end-users: Status = 1 AND ( End_Date is null OR End_Date > Date() ) To implement that logic, I tried: rs.Filter = "Status = 1 AND ( End_Date = null OR End_Date > #" & Date() & "# )" but I get

How to return a recordset from a function

淺唱寂寞╮ 提交于 2019-12-01 06:07:47
I'm building a data access layer in Excel VBA and having trouble returning a recordset. The Execute() function in my class is definitely retrieving a row from the database, but doesn't seem to be returning anything. The following function is contained in a class called DataAccessLayer. The class contains functions Connect and Disconnect which handle opening and closing the connection. Public Function Execute(ByVal sqlQuery As String) As ADODB.recordset Dim rs As ADODB.recordset Set rs = New ADODB.recordset Dim recordsAffected As Long ' Make sure we're connected to the database. If Connect Then

Looping through recordset with VBA

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 01:02:07
I am trying to assign salespeople (rsSalespeople) to customers (rsCustomers) in a round-robin fashion in the following manner: Navigate to first Customer, assign the first SalesPerson to the Customer. Move to Next Customer. If rsSalesPersons is not at EOF, move to Next SalesPerson; if rsSalesPersons is at EOF, MoveFirst to loop back to the first SalesPerson. Assign this (current) SalesPerson to the (current) Customer. Repeat step 2 until rsCustomers is at EOF (EOF = True, i.e. End-Of-Recordset). It's been awhile since I dealt with VBA, so I'm a bit rusty, but here is what I have come up with,

Retrieve ADO Recordset Field names (Classic ASP)

感情迁移 提交于 2019-11-30 19:57:49
I wonder if someone can help: Long story short, I'm using MSSQL2005 to build a Pivot table. The data being examined is limited by date range (All data for 1 week starting from the nearest Monday to the date selected) When I run the Stored Proc and pass it a date, I get The correct table back eg: Time | 1 Jan 09 | 2 Jan 09 | 3 Jan 09 | ... 09:00 | 0 | 9 | 25 | ... 09:30 | 8 | 27 | 65 | ... 10:00 | 20 | 44 | 112 | ... (Apologies for the atrocious "table" formatting). The only problem I have is that the column headers will vary based on both the date passed in to the SP (The desired view date)

Looping through recordset with VBA

我的未来我决定 提交于 2019-11-30 19:44:52
问题 I am trying to assign salespeople (rsSalespeople) to customers (rsCustomers) in a round-robin fashion in the following manner: Navigate to first Customer, assign the first SalesPerson to the Customer. Move to Next Customer. If rsSalesPersons is not at EOF, move to Next SalesPerson; if rsSalesPersons is at EOF, MoveFirst to loop back to the first SalesPerson. Assign this (current) SalesPerson to the (current) Customer. Repeat step 2 until rsCustomers is at EOF (EOF = True, i.e. End-Of

MS Access Form Bound to ADO Disconnected Recordset

那年仲夏 提交于 2019-11-30 06:01:30
问题 I seem to be clueless on this subject. I can attach an ADO recordset to a form, but I am not sure how to handle updates. I don't want to only UpdateBatch, I want to be able to detect what was changed for logging purposes. Can anyone point me in the right direction? The supplied SQL contains one Key field which is an Autonumber named "ID". Private Sub Form_Load() Dim rst as Object Set rst = CreateObject("ADODB.Recordset") rst.CursorLocation = adUseClient '...edit out connection rst.Open sql,