Home
Forums
New posts
Search forums
Articles
Latest reviews
Search resources
Members
Current visitors
Newsgroups
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Newsgroups
Microsoft Excel
Microsoft Excel Programming
Exporting data with vba from Excel to an Access 2007 db with password
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="GS, post: 14132880"] Jan T has brought this to us : You could have found an answer already posted here if you browsed the subject lines for DB related topics. I use a version-aware function to set up my connection string according to which provider is appropriate for the running instance of Excel. Otherwise, everything else is the same as far as building queries/recordsets goes. Example: Construct a connection string something like this: If Application.Version => 12 Then 'use ACE provider connection string Else 'use JET provider connection string End If This precludes that you'll have to construct 2 separate connection strings. You could use constants for this: Const sProvider As String = "Microsoft.Jet.OLEDB.4.0;" Const sExtProps As String = "Excel 8.0;" Const sProvider12 As String = "Microsoft.ACE.OLEDB.12.0;" Const sExtProps12 As String = "Excel 12.0 Xml;" If you know the data source beforehand, you could configure your code something like this: <aircode> ' Use a var to hold data source sDataSource = "<FullPathAndFilename>" If Application.Version => 12 Then 'use ACE provider connection string sConnect = "Provider=" & sProvider12 & _ "Data Source=" & sDataSource & _ "User ID=" & sUsername & ";" & _ "Password=" & sPassword & ";" Else 'use JET provider connection string sConnect = "Provider=" & sProvider & _ "Data Source=" & sDataSource & _ "User ID=" & sUsername & ";" & _ "Password=" & sPassword & ";" End If </aircode> ' Construct your SQL statement sSQL = "SELECT * FROM..." ' Grab the data into a recordset Set rsData = New ADODB.Recordset rsData.Open sSQL, sConnect, adOpenForwardOnly, adLockReadOnly, adCmdText [/QUOTE]
Verification
Post reply
Home
Forums
Newsgroups
Microsoft Excel
Microsoft Excel Programming
Exporting data with vba from Excel to an Access 2007 db with password
Top