Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6917091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:41:11+00:00 2026-05-27T09:41:11+00:00

Preface I have a Access 2010 front-end with a MySQL back-end. I want to

  • 0

Preface

I have a Access 2010 front-end with a MySQL back-end. I want to use a default MySQL user-name to initially connect to the back-end DB and do password checks etc then switch to a user specific MySQL user-name.

I have already created code to change the connection string and reconnect the MySQL tables with the new user-name but Access annoyingly keep remembering the original user-name and password and uses that one.

Question

How can I force MS Access 2010 to forget the original user-name and password to connect to an ODBC and use the new one in the connection string?

Replication

To recreate my problem

  • MySQL:
    • Create a new schema called “test”
    • Create 3 tables on the new schema:
      • “table1”
      • “table2”
      • “table3”
    • Create two new users that have access to that schema:
      • Name: “SQLUser1”, Pass: “Pass01”
      • Name: “SQLUser2”, Pass: “Pass02”
  • Access End:
    • Create a new MS Access 2010 project
    • Create a new empty form
      • Add 2 buttons called “Cmd_User1” and “Cmd_User2”
    • Add the example code below
      • You will need to correct the server name (sServer = “MySQL”) in GenConString() function.
    • Run the form
    • Click “Cmd_User1” button
    • Click “Cmd_User2” button
  • Now check the MySQL logs and it will have used user: “SQLUser1” for both connections 🙁

Example Code:

Option Compare Database
Option Explicit

Private Sub Cmd_User1_Click()
    'Remove all existing tables
    Call RemoveAllTables
    'Connect the tables
    Call AttachDSNLessTable("table1", "table2", GenConString("SQLUser1", "Pass01"))
    Call AttachDSNLessTable("table2", "table2", GenConString("SQLUser1", "Pass01"))
    Call AttachDSNLessTable("table3", "table3", GenConString("SQLUser1", "Pass01"))
End Sub

Private Sub Cmd_User2_Click()
    'Remove all existing tables
    Call RemoveAllTables
    'Connect the tables
    Call AttachDSNLessTable("table1", "table1", GenConString("SQLUser2", "Pass02"))
    Call AttachDSNLessTable("table2", "table2", GenConString("SQLUser2", "Pass02"))
    Call AttachDSNLessTable("table3", "table3", GenConString("SQLUser2", "Pass02"))
End Sub

Private Sub RemoveAllTables()
    Dim bFound As Boolean, TblDef As DAO.TableDef
    bFound = True 'Force to loop once
    While (bFound = True)
        bFound = False
        For Each TblDef In CurrentDb.TableDefs
            If Not (TblDef.Connect = "") Then
                Call CurrentDb.TableDefs.Delete(TblDef.Name)
                bFound = True
            End If
        Next TblDef
    Wend
End Sub

Private Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stConnect As String)
    On Error GoTo AttachDSNLessTable_Err

    Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
    CurrentDb.TableDefs.Append td
    AttachDSNLessTable = True
    Exit Function

AttachDSNLessTable_Err:
    AttachDSNLessTable = False
    MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description
End Function

Private Function GenConString(ByVal sUserName As String, ByVal sPassword As String) As String
    Dim sConString As String, sServer As String, sDatabase As String, iPort As Integer
    'Pull back all the required fields
    sServer = "MySQL"
    sDatabase = "test"
    iPort = "3306"
    'Generate connection string
    sConString = "ODBC;Driver={MySQL ODBC 5.1 Driver}; " _
                & "Server=" & sServer & "; " _
                & "Database=" & sDatabase & "; " _
                & "UID=" & sUserName & "; " _
                & "PWD=" & sPassword & "; " _
                & "Port=" & iPort & "; " _
                & "Option=3"
    'Return new connection string
    GenConString = sConString
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:41:12+00:00Added an answer on May 27, 2026 at 9:41 am

    I reckon your best approach is to only have one connection to your MySQL database, using your second username. As for the original connection when you are checking the passwords etc, could you not save a pass-through query with the first username and run with that?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Preface: I have a MS Access 2010 front end running against a MySQL back
Preface: I have a rolling upgrade to SharePoint 2010 in progress for one of
Preface: I have two entities defined as a one-to-many relationship: A <<-------> B. B's
Preface: I am sure this is incredibly simple, but I have searched this site
Let me preface this question. I have just started using jquery, so please be
A quick preface, I'm very comfortable in .Net, but have limited experience in c++,
Preface: I have a demo of the problem on my personal site (I hope
Preface I have three tables Customers, Individuals & Companies and a customer can be
Preface: This is the first real swing program I have done. I have a
I'll preface this question by stating I have historically used tables for my HTML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.