recordset

recordset.find using variable VBA ADODB

六眼飞鱼酱① 提交于 2019-12-24 01:12:28
问题 I am getting pretty desperate trying to get this trivial search to work: rst2.Find "ID = '" & messID & "'" I have tried just about any combination but it just never returns a search result. the whole code would be here: Option Compare Database Option Explicit 'Modul zum Updaten des Status eines Messmittels in der Stammdatenbank (Entnommen/Verfügbar)3 Public Function updateStatus() Dim rst2 As ADODB.Recordset Dim rst As ADODB.Recordset Dim messID As String Set rst = New ADODB.Recordset

How to specify Primary Key when using vba to create tables

泪湿孤枕 提交于 2019-12-23 18:48:13
问题 I've updated the code with the suggestion given below, which I've tested and works great, for quick reference for future users. I'm using the below code to create linked tables without having to set up a DSN for each user, how can I specify a primary key as you would be asked if connecting manually: Dim sConnect As String Dim db As DAO.Database Dim tdf As DAO.TableDef Set db = CurrentDb Set tdf = db.CreateTableDef tdf.Name = "dbo_vwFeedback" ' - -- --- This is the Label that you see in Access

Excel VBA - Loop through recordset

这一生的挚爱 提交于 2019-12-23 04:45:15
问题 I have an issue when looping through a recordset; here is the code: Dim query as String query = "SELECT * FROM test WHERE " & filter ' Declare variables' Dim objMyConn As ADODB.Connection Dim objMyCmd As ADODB.Command Dim objMyRecordset As ADODB.Recordset Dim objRst As ADODB.Recordset Set objMyConn = New ADODB.Connection Set objMyCmd = New ADODB.Command Set objMyRecordset = New ADODB.Recordset 'Open Connection' objMyConn.ConnectionString = "Provider=SQLOLEDB;Data Source=MyServer;Initial

SQL Statement to create a table as a result of a count operation?

守給你的承諾、 提交于 2019-12-23 03:47:22
问题 Let's say you got a table like this id terms 1 a 2 c 3 a 4 b 5 b 6 a 7 a 8 b 9 b 10 b and you want to end up with a report like this; terms count a 4 b 5 c 1 So you run this over the first table SELECT terms, COUNT( id) AS count FROM table GROUP BY terms ORDER BY terms DESC So far so good. But the above SQL statment puts the report view on the browser. Well, I want to save that data into a SQL. So, what SQL command do I need to insert the results of that report into a table? Assume that you

How to populate a ListBox with a ADODB.Recordset (Error 91) To Do Autocompletion in Access

一笑奈何 提交于 2019-12-22 05:03:05
问题 I work on an Access DB and I have to use a Datasource connection to a SQL Server. To do that I use the ADODB object with : -ADODB.Connection -ADODB.Recordset Code Up-to-date, following an observation of Ian Kenney Dim cnn As ADODB.Connection Set cnn = New ADODB.Connection Dim rs As ADODB.Recordset cnn.ConnectionString = "driver={SQL Server};provider=SQLOLEDB;server=10.****;uid=****readonly;pwd=****readonly;database=****" cnn.Open Set rs = cnn.Execute("SELECT [MATRI], [NOMPRE] FROM SCHEME_DB

Excel VBA function with Recordset (Performance issue)

家住魔仙堡 提交于 2019-12-20 06:38:30
问题 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

Why should I close and destroy a recordset?

人走茶凉 提交于 2019-12-20 04:38:17
问题 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? 回答1: rs.close cleans up the resources that are used internally, however because ASP is a single process that doesn't have any GC the

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

走远了吗. 提交于 2019-12-20 02:42:28
问题 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

WHERE IN Query with two recordsets in Access VBA

♀尐吖头ヾ 提交于 2019-12-19 11:46:08
问题 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

VBA - Create ADODB.Recordset from the contents of a spreadsheet

前提是你 提交于 2019-12-18 04:20:57
问题 I am working on an Excel application that queries a SQL database. The queries can take a long time to run (20-40 min). If I've miss-coded something it can take a long time to error or reach a break point. I can save the results to a sheet fine, it's when I am working with the record sets that things can blow up. Is there a way to load the data into a ADODB.Recordset when I'm debugging to skip querying the database (after the first time)? Would I use something like this? Query Excel worksheet