adodb

ADODB query timeout

不羁岁月 提交于 2019-11-29 17:34:58
问题 I am trying to open a query, which is timing out. I have tried setting the timeout property, but it doesn't seem to want to accept it. The query takes 34 seconds to execute using MS-SQL Server Management window (SQL Server 2005), so I know I need to increase the timeout. Current code: Public Function retRecordSet(StrSQL) Dim cmd ' as new ADODB.Command Dim rs 'As New ADODB.Recordset Set cmd = CreateObject("ADODB.Command") Set rs = CreateObject("ADODB.Recordset") cmd.ActiveConnection =

Fast update of Access data with Excel data using Excel VBA

落花浮王杯 提交于 2019-11-29 16:46:28
By "fast" I mean using the UPDATE SQL query as opposed to looping through every recordset. Here I found this nice query: ''Batch update (faster) strSQL = "UPDATE [;Database=c:\Docs\DBFrom.mdb;].Table1 t " _ & "INNER JOIN [Sheet7$] s " _ & "ON s.id=t.id " _ & "SET t.Field1=s.Field1 " _ & "WHERE s.Field1<>t.Field1 " cn.Execute strSQL However, this example is used while connected from Access VBA to pull data from Excel to Access. In my case I would need to connect from Excel VBA and using data from that same Excel file ( named range without headers ) update Access data. The data has exactly the

VBA function in Excel ADODB query

折月煮酒 提交于 2019-11-29 14:47:11
I'm opening an ADODB connection in Excel 2007 to query one of the worksheets of the current workbook. When trying to add a custom VBA function, an error raises "Undefined function name". The connection: Dim connection As String Dim records As ADODB.Recordset Dim query As String Dim fileName As String fileName = ThisWorkbook.FullName connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & fileName & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"";" query = "select t.[Col1] from [Sheet1$] As t" Set records = New ADODB.Recordset records.Open query, connection Sheets(2).Range("A1")

Connection string for Access to call SQL Server stored procedure

≯℡__Kan透↙ 提交于 2019-11-29 12:50:26
Using Access 2007, I want to call a stored procedure with one input parameter that returns a recordset. Using ADODB, this is pretty straightforward except for the connection string. I want to be able to derive the server and database names from a particular table, which always points to the correct server and database. (I reconnect to development dbs from time to time for testing by relinking the 100 or so linked tables.) Is there a way to get the server and database name from the tabledef without parsing the whole thing out? Is there a property? I haven't found one yet.... Final query is

associative array in vba like php

纵饮孤独 提交于 2019-11-29 12:46:53
I need your help for building analytics in Microsoft Excel using VBA. I have one data sheet with y columns and n lines Line Number Firstname Lastname Country Training Hours Training Status 1 John Smith USA 1 Completed 2 Henri Dupont France 1 Completed 3 Paul Walker USA 25 Incomplete 4 Ron Howard USA 10 Completed And I would like to use array like in php but using VBA For i = 1 To nblines If(array[i]["Country"] = "USA" And array[i]["Training Status"] = "Completed") Then myval = myval + array[i]["Training Hours"] End If Next myval should be 11 Unfortunately I don't find THE solution. I've tried

Using ADODB to access opened xls file

╄→гoц情女王★ 提交于 2019-11-29 11:23:19
Although I've been working with VBA for Excel for quite a long time, I've one problem I cannot solve by myself. I've described it below, hope to get some help or advice. I'm using Excel 2007 and Windows XP, all updated with newest patches. I'm very often using following code to get data from another workbook: Set conn = New ADODB.Connection conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=g:\source.xls;Extended Properties=Excel 8.0;" Sql = "SELECT Field1, Field2 FROM [Sheet1$]" Set rst = New ADODB.Recordset rst.Open Sql, conn, adOpenForwardOnly Worksheets("Results").Range("A2")

How to retrieve data from Excel with ADODB connection if the first line of the worksheet does not have the column name?

眉间皱痕 提交于 2019-11-29 11:15:20
I use the following type of code to retrieve data from some Excel Workbooks (path is a Parameter) Dim strSQL As String, conStr as String Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & path & "';" & _ "Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;"";" strSQL = "SELECT [Field1], [Field2] FROM [Worksheet$] WHERE [Thing1] > 1" cnn.open conStr rs.Open query, cnn, adOpenStatic, adLockOptimistic, adCmdText That code works fine if the names of the fields are on the first row of the worksheet. The problem is that I need to

How to set “Application Name” in ADODB connection string

强颜欢笑 提交于 2019-11-29 10:25:27
In .NET I simply use Application Name = MyApp inside the connection string, but when using ADO connection through VBA the Activity Monitor of the SQL Server Management Studio always shows Microsoft Office 2010 in Processes on the Application column no matter what name I set on the VBA code. conn.ConnectionString = "UID=" & UID & ";PWD=" & PWD & ";DSN=" & DSN & _ ";Application Name = MyApp" How can I set the application name for monitoring purposes? Ahh I see VBA connection string doesn't support the Application Name attribute. It simply isn't being recognized when used within VBA. The only way

“Not enough storage is available to complete this operation” when base64-encoding a zip file

房东的猫 提交于 2019-11-29 07:56:26
The below code is for converting a zip file to base64 format. Dim inByteArray, base64Encoded, Const TypeBinary = 1 inByteArray = readBytes("F:path/file.zip") base64Encoded = encodeBase64(inByteArray) Private Function readBytes(file) Dim inStream ' ADODB stream object used Set inStream = CreateObject("ADODB.Stream") ' open with no arguments makes the stream an empty container inStream.Open inStream.Type = TypeBinary inStream.LoadFromFile(file) readBytes = inStream.Read() End Function Private Function encodeBase64(bytes) Dim DM, EL Set DM = CreateObject("Microsoft.XMLDOM") ' Create temporary

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

大憨熊 提交于 2019-11-29 05:14:07
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 in MS-Access VBA (using ADODB recordset) I had to install the MDAC to get the msado15.dll and once I