unable to remove password from Microsoft Access 2007 (accdb) - ms-access

I have a Microsoft Access 2007 (accdb) file. I set a password on it. When I open it up now, I am prompted for a password. I enter the correct password and I can gain access to it.
However, I want to remove the password. I click "Database tools", but in the database tools, I only see "Encrypt with password", contrary to the help file (which says I should see "decrypt password.")
It appears that the Access UI thinks I have no password, so it won't give me the option to remove the password.
How can I get the password removed?

Create a new Access database
Create a new Form
Create Command button
execute below code (change code to reach your database and password)
Public Sub Command0_Click()
Dim objConn As ADODB.Connection
Dim strAlterPassword As String
On Error GoTo ChangeDBPassword_Err
' Create the SQL string to change the database password.
' Here, "It" is the old password, and I am wanting to set the password to NULL
' Replace "It" with your password
strAlterPassword = "ALTER DATABASE PASSWORD NULL [It];"
' Open the secured database.
Set objConn = New ADODB.Connection
With objConn
.Mode = adModeShareExclusive
.Provider = "Microsoft.ACE.OLEDB.12.0"
' Replace "It" with your old password
.Properties("Jet OLEDB:Database Password") = "It"
'The following specifies the location of the database of which PW I'm trying to change.
' Replace path to your database
.Open "Data Source= G:\Database\database.accdb;"
' Execute the SQL statement to change the password.
.Execute (strAlterPassword)
End With
' Clean up objects.
objConn.Close
Set objConn = Nothing
ChangeDBPassword_Err:
MsgBox Err.Number & ":" & Err.Description
End Sub
THANKS TO ERIC MATTHEW VAJENTIC

Did you open the database in "exclusive mode"?
File | Open | select database file |
Triangle Next to the "Open" command
button | Open Exclusive

Related

How to link tables with VBA code over ODBC

Actually I use a ODBC-Connection to connect Ms Acces to tables of a PostgreSQL-DB. I connect them by using the External Data/Import ODBC-Link command. It works fine.
But how can I use VBA to link my tables?
When using VBA to link a table with ODBC, you can add and APP= argument to specify an application name that will generally show in the properties of the connection on your database server.
For example, here is a sample ODBC Connection string for a linked table:
ODBC;Driver={SQL Server};Server=MyServer\SQLExpress;Database=MyDatabase;APP=My App Title;Trusted_Connection=Yes;
My App Title is the string that will be your Application Name for that connection.
Update 1 In response to further comment by the OP:
Here is sample code to link a table via ODBC in VBA. To facilitate this, you also should always delete the ODBC linked table each time before re-linking it to make sure that your options are respected, and that Microsoft Access updates the schema for the linked table. This example shows a connection string for a SQL Server database, so all you would need to change is the connection string for your PostgreSQL-DB. The remaining VBA code would be the same.
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strConn As String
Dim ODBCTableName as String
Dim AccessTableName as String
Set db = CurrentDb()
ODBCTableName = "dbo.YourTable"
AccessTableName = "YourTable"
strConn = "ODBC;Driver={SQL Server};Server=YOURSERVER\SQLINSTANCE;Database=MYDATABASE;Trusted_Connection=No;UID=MyUserName;PWD=MyPassword"
db.TableDefs.Refresh
For Each tdf In db.TableDefs
If tdf.Name = AccessTableName Then
db.TableDefs.Delete tdf.Name
Exit For
End If
Next tdf
Set tdf = db.CreateTableDef(AccessTableName)
'===============================
'If your connection string includes a password
'and you want the password to be saved, include the following 3 lines of code
'to specify the dbAttachSavePWD attribute of the TableDef being created
'If you don't want to save the password, you would omit these 3 lines of code
'===============================
If InStr(strConn, "PWD=") Then
tdf.Attributes = dbAttachSavePWD
End If
tdf.SourceTableName = ODBCTableName
tdf.Connect = strConn
db.TableDefs.Append tdf
For some reason this code gives Run time error 3170 - Could not find installable ISAM. However, when you add ODBC; at the beginning of the connection string, then it works. So the connection string should look something like:
strConn = "ODBC;DRIVER={MySQL ODBC 5.2 Unicode Driver};" _
& "SERVER=servername;" _
& "DATABASE=databasename;" _
& "UID=username;PWD=password; OPTION=3"

Error while connecting to Access from Excel 2010

I wrote the following VBA code in Excel 2000 to create a connection to an Access 2000 with workgroup security in WindowsXP. Everything was working properly until we moved to Windows7 The database is still in Access2000.
It seems that the password value is eliminated from the ADODB connection string after opening a connection to the database. The first debug.print statement of the code below returns a string that contains the password and the user name but the second debug.print statement only shows the value of the User ID parameter. As a result when I try to create a recordset I get an error message that I do not have permission to the data.
Following the exact same procedure from Excel 2000 in Windows XP the ADODB connection string was not eliminating the password value and I was able to open a recordset.
Any suggestions?
Public Function sDbConnection() As String
Dim sString As String
Dim sConnection As String
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.Provider = "Microsoft.Jet.OLEDB.4.0;"
' Provide path to the system Db
conn.Properties("Jet OLEDB:System database") = "S:\UTL\RscMgmt\SECURE.MDW"
' Username and password to the secured access database
conn.Properties("Password") = "MyPassword"
conn.Properties("User Id") = "MyUserID"
Debug.Print conn.ConnectionString
' Open a connection to the Access 2000 db and return the connection string
conn.Open "Data Source=" & "S:\UTL\RscMgmt\GasPortfolio 2000.mdb" & ";"
sConnection = conn.ConnectionString
Debug.Print sConnection
sDbConnection = sConnection
End Function
If you are on a 64 bit version of Win 7, the Microsoft.Jet.OLEDB.4.0 provider will not work, as it is only for 32-bit systems.
This website lists a few work-arounds you can implement.
Try it with "Microsoft.ACE.OLEDB.12.0" provider .

vb.net application login using mysql database

im trying to let users login to an application i created in vb.net using the user table of the application's database in mysql
i heard that The usual way to do this is to have just one MySQL user called "[my_app_name]" with the relevant permissions. Then my application uses it's own user table to control access to the application, and the one MySQL user to access the database. but i dont know how to do it, can someone please help me with it. im new to all this.
thanks
If you're making a login form that will check for authetication with users and their passwords on a MySQL database just follow this code I wrote for my own login form.
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Dim conn As MySqlConnection
'Connect to the database using these credentials
conn = New MySqlConnection
conn.ConnectionString = "your server goes here; user id=userid goes here; password=self explanatory; database=the database where the credential information is located"
'Try and connect (conn.open)
Try
conn.Open()
Catch myerror As MySqlException 'If it fails do this... (i.e. no internet connection, etc.)
MsgBox("Error connecting to database. Check your internet connection.", MsgBoxStyle.Critical)
End Try
'MySQL query (where to call for information)
Dim myAdapter As New MySqlDataAdapter
'Tell where to find the file with the emails/passes stored
Dim sqlquery = "SELECT * FROM your database with info WHERE Email = '" & txtEmail.Text & "' AND Password = '" & txtPassword.Text & "'"
Dim myCommand As New MySqlCommand
myCommand.Connection = conn
myCommand.CommandText = sqlquery
'Start query
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader
'See if the user exists
If myData.HasRows = 0 Then
MsgBox("Invalid email address or password.", MsgBoxStyle.Critical)
'Insert your settings change here. (i.e. My.Settings.LoggedIn = False)
Else
MsgBox("Logged in as " & txtEmail.Text & ".", MsgBoxStyle.Information)
'Another settings change: My.Settings.LoggedIn = True
Me.Close() 'close the login form
End If
Be sure to change the control names and also add a setting.
Open up MySQL Workbench and towards the bottom right of the first screen, under the "Server Administration" column, you'll see "Manage Security". Click on that. In the menu to the left you will see "Users and Privileges". Click on that. You'll see a button that says "Add Account" which, when clicked, will allow you to create a new user. In the Schema Privileges tab you can modify the user's permissions.
The user you created here can be used in your connection string. Here is an example MySQL connection string from one of my applications. The username in the connection string below, repair, was created with "Login Name:" as "repair" and "Limit Connectivity to Hosts Matching:" as "%".
"Server=10.0.0.113;uid=repair;pwd='password&92';database=repair"
I hope this helps. Have a great day.

Editing Linked Table Information In Access 2003

I have an Access 2003 database with linked tables to a SQL Server 2005 database. The user information (the password) that is used to create an ODBC connection between Access and SQL Server was recently updated.
When I open the Access database, and try to edit the Linked table information I am then able to open the tables and see my data. However, when I close Access and and reopen the Access database it appears the password informtion has revereted back and I get an ODBC connection error.
Anyone know what I am doing incorrectly?
As a follow up, it appears we have about a dozen Access databases with numerous linked tables that all need this update. Is this the best way to update this information? The linked tables seem to have been created using different machines as the Workstation-ID specified in the ODBC connection is different.
Write a routine, that update the Connect Property from the TableDef and save the change with RefreshLink.
The problem with Linked Table Manager (LTM), is when you have linked tables that are in fact links to SQL Views. In that case, LTM will relink the "tables" without reassigning them the proper PK, and they will become non updatable.
I have written some code that I used to start from VBE, it is a quick and dirty thing, but you could surely adapt that if you need it.
There are 2 subs, one for the tables, and one for the passthru queries.
Option Compare Database
option explicit
Const kOld = "remote.g" 'string to identify old server
'new server odbc string
Const kConnLux = "ODBC;DRIVER=SQL Server Native Client 10.0;SERVER=xxxx;UID=yyyy;PWD=zzzz;"
Sub UpdateTables()
Dim db As Database, td As TableDef
Dim hasIndex As Boolean, strSql As String
Set db = CurrentDb
For Each td In db.TableDefs
If InStr(1, td.Connect, kOld) > 0 Then 'lien vers CE serveur ?
If td.Name Like "dbo_vw*" And td.Indexes.count = 1 Then 'table = vue attachee --> pbl de clef primaire
strSql = "CREATE INDEX " & td.Indexes(0).Name & " ON [" & td.Name & "](" & td.Indexes(0).Fields & ")"
' convert field list from (+fld1;+fld2) to (fld1,fld2)
strSql = Replace(strSql, "+", "")
strSql = Replace(strSql, ";", ",")
hasIndex = True
Else
hasIndex = False
End If
td.Connect = kConnLux
td.RefreshLink
Debug.Print td.Name
If hasIndex And td.Indexes.count = 0 Then
' if index now removed then re-create it
CurrentDb.Execute strSql
End If
End If
Next td
Debug.Print "Done"
End Sub
Sub UpdateQueries()
Dim db As Database
Dim td As QueryDef
Set db = CurrentDb
For Each td In db.QueryDefs
If InStr(1, td.Connect, kOld) > 0 Then
td.Connect = kConnLux
Debug.Print td.Name, td.Connect
End If
Next td
End Sub

Can I add a user to Access with VBA, instead of using the builtin User and Group Account box?

While making an access database, I'd like to make it as idiot proof as possible. This means, I don't want the client to have to use the access components; I'd rather have my own form that just takes a username and password and adds it to the correct groups automatically.
I thought I had some code that would work:
Dim usr as User
set usr = new User
usr.Name="Foo"
'set other properties'
DBEngine.Workspace(0).Users.Append(usr)
but it tells me that the operation is not supported. Is there any other way to get a new user inserted into the security file?
Use DDL to create user "fred" with password "pword":
CurrentProject.Connection.Execute "CREATE USER fred pword;"
Add fred to Users and Admins groups:
CurrentProject.Connection.Execute "ADD USER fred TO Users;"
CurrentProject.Connection.Execute "ADD USER fred TO Admins;"
MSDN documentation for Data Definition Language here:
http://msdn.microsoft.com/en-us/library/bb267262.aspx
You can use "ALTER USER ..." to change password, and "DROP USER ..." to delete the user.
Which access version are you using. Are you just trying to add a new user to a group/new group.
I found this example on Access 2003, and it seemed to work just fine
Sub CreateUserX(ByRef strPassword As String)
Dim wrkDefault As Workspace
Dim usrNew As user
Dim grpNew As Group
Dim usrTemp As user
Dim prpLoop As Property
Dim grpLoop As Group
Set wrkDefault = DBEngine.Workspaces(0)
With wrkDefault
' Create and append new User.
Set usrNew = .CreateUser("NewUser")
usrNew.PID = "AAA123456789"
usrNew.Password = strPassword
.Users.Append usrNew
' Create and append new Group.
Set grpNew = .CreateGroup("NewGroup", _
"AAA123456789")
.Groups.Append grpNew
' Make the user "NewUser" a member of the
' group "NewGroup" by creating and adding the
' appropriate User object to the group's Users
' collection.
Set usrTemp = _
.Groups("NewGroup").CreateUser("NewUser")
.Groups("NewGroup").Users.Append usrTemp
Debug.Print "Properties of " & usrNew.Name
' Enumerate the Properties collection of NewUser. The
' PID property is not readable.
For Each prpLoop In usrNew.Properties
On Error Resume Next
If prpLoop <> "" Then Debug.Print " " & _
prpLoop.Name & " = " & prpLoop
On Error GoTo 0
Next prpLoop
Debug.Print "Groups collection of " & usrNew.Name
' Enumerate the Groups collection of NewUser.
For Each grpLoop In usrNew.Groups
Debug.Print " " & _
grpLoop.Name
Next grpLoop
' Delete the new User and Group objects because this
' is a demonstration.
.Users.Delete "NewUser"
.Groups.Delete "NewGroup"
End With
End Sub
Will that be helpfull?
After much hair pulling and an epic battle against lacking documentation, here it is. You must use ADOX. Link it in in the references menu in the VBA editor.
Dim cat as ADOX.Catalog
Dim user as ADOX.User
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
usr = new ADOX.User
usr.Name = "joe"
cat.Users.Append usr
' must change password on user after inserted '
cat.Users("joe").ChangePassword "", "pass"
cat.Users("joe").Groups.Append "Users" ' have to be in this to open database '
cat.Users("joe").Groups.Append "MyCustomGroup"
Set cat = Nothing
Set usr = Nothing
There are other Objects that have connection objects. They do not work. CurrentProject.Connection is the only one that worked for me.
Some documentations show a change password on the user object before appending it to the Users catalog. That did not work right.
The various documentations seemed to show that the Users Collection could do this, but it could not append - it needs the ADOX Catalog for that.
This MSDN article covers what you are trying to do:
http://msdn.microsoft.com/en-us/library/aa190108(v=office.10).aspx
Ironicly, the other three answers each cover one of the approaches: DDL, DAO, and ADOX.