Creating a Connection String with option - HDR=NO - vba

note: I realize this question is similar to 512143, but this is in Excel only.
Although I could do this other ways, I wanted to learn the technique in This Article, which uses a recordset to transfer data. My problem is this: I don't have headers on my data (well, they are on the left... not above) so I was mysteriously NOT getting my first row into my template worksheet. I narrowed the issue down to the connection string NOT specifying the absence of headers.
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ActiveWorkbook.FullName & ";Extended Properties=Excel 12.0;"
connDB.Open connStr
when I change it to:
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ActiveWorkbook.FullName & ";Extended Properties=Excel 12.0;HDR=NO;"
I get the "Could not find installable ISAM" error, which I don't understand.
I searched for answers and found questions: 37251084, 512143
So I tried:
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ActiveWorkbook.FullName & ";Extended Properties='Excel 12.0;HDR=NO;'"
which gave the error: "Format of initializing string does not conform to OLE DB specifications"
so now I will either give up (which is no good since I have to integrate this data system into Access eventually and should understand this type of thing.)
or do some makeshift fix where there are blank headers above the data. Which is lame.
After a few hours of searching for something I can understand relating to connection strings I am kinda spent, any help is appreciated.

This provider string worked on: Microsoft Excel 2016 MSO (16.0.9126.2109) 32-bit
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ActiveWorkbook.FullName &
";Extended Properties='Excel 12.0;HDR=NO;IMEX=1'"
for the full technique, I give credit to Felix Hooker at Datanumen. Here he gives the full code, which I found useful as a macro for creating saved data files from template in a scientific type data processing spreadsheet, without flashing windows open and closed when the user clicks a button!

Related

How to resolve a connection problem when connecting SQL from VBA XLS " ; VBA error message= 'Not able to find ISAM file'

when setting and running ADODB connection to SQL from VBA xls, I got a error message "Not able to find the ISAM file", I writting the following connection in a VBA Module :
"Provider= Microsoft.ACE.OLEDB.12.0
"Data Source=" & PWRQRYFilePath
Im usiging xls 2019 , 32 bits. Referencing to Microsoft ActiveX Data Objects 6.1 Library.,
check any thing but not able to create and open the connection would you please help me.
Im trying to create and open the connection so I can run SQL queries from VBA xls
Following is a simple query i want to run to obtain a join inner from two spread sheets
But Actually the Query is sending me the error message.
What is the content of the variable PWRQRYFilePath?
For the sake of completeness:
If you want to go the long way, or better spoken, if you need the query more times, as you know, you can put the code lines also in a function an pass the path to the file to it.... here its represented by the Workbook-Property ThisWorkbook.Fullname
Dim rs As Object 'or AS ADODB.Recordset for EarlyBinding/IntelliSense
With rs
.Open "SELECT * FROM [worksheetname$] WHERE [column]='value'", _
";Provider=Microsoft.Ace.OLEDB.12.0" & _
";Extended Properties""Excel 12.0 xml""" & _
";Data Source=" & ThisWorkbook.FullName
'*** do your stuff with recordsetresult
.Close
End With
If you need the query just once, you can use a anonym function call as well:
With CreateObject("ADODB.Recordset")
.OPEN ...
'*** do your stuff ...
.CLOSE
End With

submit data from excel userform to password protected access database

i am trying to submit userform data from excel (2013) to an access database.
without password, this code works fine.
Private Sub Addoer_Click()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim dbPath
dbPath = Sheet16.Range("K18").Value
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data source=" & dbPath
Now i am trying to use same method to send data from excel to a password protected database (each user has different password). In the excel file, the user id is at Sheet16.Range("K17") and password is at Sheet16.Range("K19")
userid = Sheet16.Range("K17").Value
pw = Sheet16.Range("K19").Value
i changed the cnn.open line to following
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data source=" & dbPath, userid, pw, -1
and I am getting this error:
Error -2147217843 (Cannot start your application.The workgroup information file is missing or open exclusively by another User.)
i changed the cnn.open line to this
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data source=" & dbPath, """ & userid & """, """ & pw & """, -1
and I get this error
Error -2147217843 (Not a valid account name or password).
Is there anybody that can help to point where did I do wrong?
Your second attempt doesn't work, because you are passing in the username as "user" when the username is actually user.
Regarding your first attempt, I found this note at connectionstrings.com:
Note! Reports say that a database encrypted using Access 2010 - 2013 default encryption scheme does not work with this connection string. In Access; try options and choose 2007 encryption method instead. That should make it work.
Also, could it be that the database is opened exclusively by another connection / program? If you have the database open in Access and you can design tables / queries, IIRC that means you have exclusive access to the database, and no other connections can connect to it. Do you see an .laccdb (or .ldb) file in the same folder as the Access database?
References:
Microsoft OLE DB Proivder for Microsoft Jet
ConnectionString Property
Formatting Rules for Connection Strings at connectionstrings.com

VBA SQL 'No value given for one or more required parameters' but field exists

I am trying to run sql queries on one spreadsheet from another in Excel 2010 VBA.
My connection is set up properly and works as expected, except for 1 column, which for some reason is giving me this error. I checked the name of the column and I also tried renaming it to something super simple, but it still still doesn't. Can anyone think of what else the issue might be. All other columns work for selecting.
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & workbookPath _
& ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";"
This is the query, it works for all other fields except the "Ticker Number" column. I tried renaming it in the source file but no luck...
sqlString = "SELECT [Ticket Number] FROM [Sheet1$A1:Z100]"
Try with this one:
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0" _
& ";Data Source=" & workbookPath _
& ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

How to read excel file in vb.net 2003

Can anyone help me on how can I read the excel file using vb.net 2003?
The first thing to do is to browse the excel file in my vb.net program then read the content of excel file and display the value of excel content in listview.
The quickest and easiest way to read an Excel file in vb.net is to use the Jet database driver.
Set cnExcel = New ADODB.Connection
cnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & MyFilename & ";" & _
"Extended Properties=""Excel 8.0;IMEX=1;HDR=NO"""
Then read through it. Here I display columns 0 and 1
rs.Open "select * from " & MySheetName, cnExcel, adOpenDynamic, adLockOptimistic
While Not rs.EOF
debug.print rs(0)
debug.print rs(1)
rs.MoveNext
Wend
An alternate way to query for data inside an Excel spreadshet is to use the interop assemblies Microsoft has released for interacting with Office apps from .NET (2003 versions here).
Using these interops is a bit more involved and you need to be careful about properly releasing the Excel objects you create to avoid leaks, but does give you more access to all the information contained with the workbook you're opening - you can see a short intro for using these assemblies here.

MS Excel connection with vb.net

I have used the connection string below but I am getting an error when trying to create a table
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFName + _
";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"""
Cannot modify the design of table 'tablename'. It is in a read-only database.
If the database is read-only, then by definition you will not be able to create any tables in it.
Make absolutely certain that you do have write access to the file. For example are you accessing this from IIS which only has limited permissions. Check the security of the directory. Try a normal File.Open() of the file in the same process.
I'm personally using the following to connect to an access database:
_source = "..\db.mdb"
Dim strconnexion As String
strconnexion = "Provider=Microsoft.Jet.OLEDB.4.0;"
strconnexion &= "User ID=Admin;Password=;"
strconnexion &= "Data source=" & _source
_cnBd = New OleDbConnection (strconnexion)
_cnBd.Open()
Hope this helps.
Your problem is the IMEX=1. That tells excel to open in "import mode" making the connection read-only. I had the same issue, weird weird stuff.
Take that out and it works like a charm.