submit data from excel userform to password protected access database - vba

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

Related

Is there a way to specify a proxy user id in a VBA Macro to connect to oracle?

I am currently trying to connect to an Oracle database from VBA. Below is the code I am running in VBA to try to establish the initial connection. Unfortunately, this code produces an “ORA-01017” error mentioning that my username/password is invalid. I have SQL Developer installed and when I try to login with the same credentials/info, I successfully connect. I also tried instead setting UID = userid in the VBA code below and the connection didn’t throw an error, but I can’t query any tables. The same thing happens if I try the same in SQL developer.
After doing some reading, it looks like the info in the brackets is my proxy user id and I need to somehow specify that separately from my UID, but I can’t figure out how I would go about that. Has anyone else had any experience with this or have any guidance? Let me know if there is any additional details I can provide.
Sub Ora_Connection()
Dim con As ADODB.Connection
Dim rs As ADODB.recordset
Set con = New ADODB.Connection
Set rs = New ADODB.recordset
StrCon = "Driver={Microsoft ODBC for Oracle}; Uid=userid[database name];Pwd=UserPWD;" & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=HostName)(PORT=1521))" & _
"(CONNECT_DATA=(SERVICE_NAME=XXXX)));"
con.Open (StrCon)
End Sub
It doesn't look like its possible to connect to proxy user with ADODB .
One another alternative is to use alter session set current_schema = Proxy_user run this after you open the session.
The only trouble with this is that the grants should be there for the actual user, here proxy user just allows us to avoid using identifiers.

Unable to connect to DB from VBA but able to connect from Access

I'm able to connect to a database using Access, but not from VBA. In Access, I use the server name, Windows NT Integrated Security,and the database name. In VBA, I've tried many variations of variable names and values in the connection string, and the db.Open command always fails. I generally get an error about not being able to find an installable ISAM, or Multiple-step OLE DB operation generated errors. Is there a way to determine what I can use as a connection string from the working Access connection? One example of code that fails with the latter error:
Dim db As Object
Dim adoRS As Object
Set db = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.recordset")
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Server=sql03;" & _
"Database=db1;" & _
"Integrated Security=SSPI;"
The provider you as using in the connection string is for MS Access.
If thats the correct database then do the following.
Add the refrence "Microsoft Office 14.0 Access Database Engine object library.
Dim cnString, query As String
Dim rs As New ADODB.Recordset
'If older version of MS access then try Provider=Microsoft.Jet.OLEDB.4.0;'
cnSTring= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<Path>;Jet OLEDB:Database Password=<Pass>;"
query = "SELECT * FROM TABLE"
rs.Open query, cnString, adOpenStatic, adLockOptimistic

My oledb connection works on a workbook but not on the other

So i have this code in two different workbooks, two different files. They are even in the same folder in the same computer.
strFile = "Z:\service\climatizacion.mdb"
strCon = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & strFile
Set cn = CreateObject("ADODB.Connection")
cn.Open strCon
strSQL = "SELECT codigorep, cantidad, precio, descripcion FROM cotizacion WHERE codigorep = " & lngInput & ";"
Set rs = CreateObject("ADODB.RECORDSET")
rs.Open Source:=strSQL, ActiveConnection:=cn, CursorType:=adOpenDynamic, LockType:=adLockOptimistic
In one of the workbooks it works perfect, it selects all the data i need from the database.
On the other it gives me the Runtime error 3001 (The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another) when I try to open the recordset.
I figured through this code that the connection was the problem (I may be wrong)
If cn.State = adStateOpen Then
MsgBox "connected"
Else
MsgBox "not connected"
End If
I cannot find the difference between these workbooks that can make this connection or the entire code work or make it stop working.
All the variables are declared, the tables exist, i can open them through access with no problems, the database is located on a pc on my local network.
The database is an mdb file, from access 97. And i'm running this on excel 2003, both workbooks, and both were created by me with the same excel 2003.
Thank you in advance for taking the time to read this :D

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

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.