How can I share an excel ODBC connection with other people? - vba

I recently developed an excel file that uses internal excel connections to update a few of the tabs from a data import tab within the workbook. Everything works great until I email it to one of my co-workers and he tries to update the data. He will get the error message below. I never set a password on the material so I am unsure why this error is occurring.
I cant add a photo (rep isn't high enough yet) but the error text is below.
Error Text
Reenter Password
The Password is missing or invalid for [name of file]. Please verify your Password and reenter it.
Connection string:
Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Users\xxxxxx;Mode=Share Deny Write;Extended Properties="HDR=YES;";Jet OLEDB:System database=;Jet OLEDB:Registry Path=;Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False

Just a guess: Since your Data Source points to a filepath, could it be that your co-worker doesnt have the file at the exact same path? Especially since that seems to live under "Users"? Maybe thats just Excel's way of telling you the file is missing?

Related

ADODB.command.Execute fails if I use a new connection

If I create a new connection, the first call to SQL, whatever it is, fails.
ConnectionString = CurrentProject.Connection.ConnectionString
Set connection = New ADODB.connection
connection.Open ConnectionString ' Fails here now
End If
If connection.STATE = adStateOpen Then
MsgBox "Success"
Else
MsgBox "Failure to communicate"
End If
connection.Execute "Select 1 from [System Log] where 1 = 0", , adCmdText Or adExecuteNoRecords
Fails with "Object variable or With block variable not set"
If I just use
Set connection = CurrentProject.connection
it works fine.
Connection string now looks like
Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Apps\AccessDB.accdb;Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database=C:\Users\user\AppData\Roaming\Microsoft\Access\System.mdw;Jet OLEDB:Registry Path=Software\Microsoft\Office\16.0\Access\Access Connectivity Engine;Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=True;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False
Normally, when you create a new connection, you are trying to connect to external data and ADO works great for that.
In this case, I wanted to work through the existing local and linked tables, just with a separate connection so I could have everything in a transaction.
I didn't want to use the existing connection because there are some things that I didn't want to get rolled back on failure, like logging.
In the end, I couldn't get this to work.
I considered moving everything to using DAO to make it easy to access the local data, but that would have been a massive and risky change.
The final version went the other way and switched the logging to using DAO and CurrentDB, while everything else continued to use ADO and CurrentProject.Connection. This way I just set the transaction on the connection and no new ADODB needed.

Insert pdf as a package from VBA, to avoid application associations

I am attempting to speed up insertion of pdf's as embedded files into a Word document.
In MS Word, from the insert object dialog, it is possible to select 'package' as an option. Doing this avoids the automatic association of the inserted file with a particular application, which is required, as not all users of this document have the same PDF reader installed.
After manually inserting a file that does not have associations, I have switched to field codes to view the class type of the inserted package, the field code reads: { EMBED Package }
So I have tried the following:
Application.Selection.InlineShapes.AddOLEObject _
ClassType:="Package", _
FileName:=FiletoInsert, _
LinkToFile:=False, _
DisplayAsIcon:=True, _
Range:=Application.Selection.Range.Next(Unit:=wdCell, Count:=1)
But the embedded file resulting from this is still associated with Foxit or Adobe applications.
On comment suggestion, I've tried the macro recorder to check the parameters input by the application when using that approach, output in Macro:
Selection.InlineShapes.AddOLEObject ClassType:="Package", FileName:="", _
LinkToFile:=False, DisplayAsIcon:=True, IconFileName:= _
"C:\WINDOWS\system32\packager.dll", IconIndex:=0, IconLabel:="Package"
I have tried changes based on this, but still including the FileName of the file to be inserted, but the application association remains.
How do I go about embedding these files without the association with an application, so that any user can open the pdf?

exportxml method stops after expor of 30% of a table, 3GB internal memory, 3TB disk, no runtime errorcode. on other machine it works perfect

exportxml method (VB-ACCESS) suddenly stops after exporting some 30% of a table, (3GB internal memory, 3TB disk, Win10, 64biy, MS-Access 2019), without even running into an errorcode. on other machine it works perfectly. any ideas?
looked at MS blogs etc, none of the proposed solutions are applicable
ChDir PEPDir & "\" & Bedrijf
'XML file exporteren
Application.ExportXML _
ObjectType:=acExportTable, _
DataSource:="PEPCOut", _
DataTarget:="PEP-ProManIT-" & MaakDate & ".xml", _
SchemaTarget:="PEP-ProManIT-Schema-" & MaakDate & ".xsd"
expect 1mio+ records to be exported, only some 300K+ are exported

ADO Recordset to Excel spreadsheet opens properly in Excel 2007, has a missing parameter in Excel 2013

My spreadsheet is reading data from another spreadsheet using ADO. The VBA code works properly in MS Excel 2007. However, in MS 2013, opening the recordset generates the error: No value given for one or more required parameters.
The line that errors out reads:
recset.Open sqlCommand, _
conn, adOpenStatic, adLockReadOnly, adCmdText
I double checked my two variables.
sqlCommand has the (sanitized) value: SELECT * FROM [Sheet1$] WHERE [F1] IS NOT NULL ORDER BY [F1] ASC.
conn is the Connection object, with (sanitized) value: Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Users\user\Documents\path\workbook_to_read.xlsx;Mode=Share Deny None;Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False;
The other three parameters are ADO constants.
My best guess is that the Provider is for the wrong version, either of Excel or ADO. I don't know what the correct version is, nor how to make the code work in both environments.
Edit and facepalm:
Most of the Excel files I'm reading from do not have headers for the first two fields. THIS ONE DOES, and I had to replace [F1] with the correct field name. Please close.
Hi i was looking for some answer i came up with this Treating data as text
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=YES;IMEX=1";
And when i run some test in Excel it shows this:
Provider=Microsoft.ACE.OLEDB.12.0 ...
Extended Properties=""HDR=YES;""; ...
Jet OLEDB:Bypass ChoiceField Validation=False;
So i think that your missing parameter must be the Extended Properties
Most of the Excel files I'm reading from do not have headers for the first two fields. THIS ONE DOES, and I had to replace [F1] with the correct field name.
(Answer pasted from my edit on 10 July 2015.)

Connecting to a access database via a Account Name and password

I'm trying to use two different methods of connecting to a database to edit data, the declaration below is working:
Dim rsConn As ADODB.Connection
rsConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& Application.StartupPath & "\VFMS_DB.mdb;" _
& "Jet OLEDB:System Database=Security.mdw", "Ads", "1234")
but now I want to do the same thing with the declaration below but I keep getting the message "Not a valid account name or password.
Dim conn As OleDbConnection
conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& Application.StartupPath & "\VFMS_DB.mdb;" _
& "Jet OLEDB:System Database=Security.mdw;Database Account=Ads;Database Password=1234;")
I pretty sure it's because of this ;Database Account=Ads;Database Password=1234; not being correct. I tried ;User ID=Ads;Database Password=1234; and also to make it look like the first statement but neither worked.
If anyone can please assist.
Thank You
According to connectionstrings.com, this is the right connection string for a Jet OLE DB 4.0 connection with username and password:
Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\mydatabase.mdb;Jet
OLEDB:System Database=system.mdw;User
ID=myUsername;Password=myPassword;
I don't know the actual answer to your problem, but would point out that there is a potential for confusion here. There are two different types of "passwords" with Jet, the database password and the Jet user-level security password. The former involves no username (the database has a single password for everyone), while the latter has username/password pairing.
Jet ULS is always in effect, at all times. The default setup with Jet is a username of "admin" with no password defined. If someone has defined a password for the admin account, you'll need to provide it, or use an account whose password you know.
Last of all, the Jet ULS information is kept in a workgroup file, usually named system.mdw, and you may need to specify that in your connection string if the security settings for the MDB you're attempting to access are stored in a workgroup file other than the one defined as the system's default workgroup file. I'm not certain how ADO/OLEDB interacts with the default workgroup location settings in the registry, so I'd suggest finding out what the parameter name is for it and specifying it explicitly in all cases.
Try using the User ID and Password keywords instead of Database Account and Database Password:
conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& Application.StartupPath & "\VFMS_DB.mdb;" & _
"Jet OLEDB:System Database=Security.mdw;User ID=Ads;Password=1234;")
This is according to an example that I found on connectionstrings.com.
Have you tried with user id and just password?
The easy way:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;Jet OLEDB:Database Password=myPassword