Home > front end >  Open ODBC from button
Open ODBC from button

Time:07-08

I have an Access 2019 database and want to include a button to open the ODBC administrator. The event procedure on click is written as

Private Sub Command210_Click()
Dim RetVal
RetVal = Shell("odbcad32.exe", 1)
End Sub

however this does not work, if I replace odbcad32.exe with notepad.exe it will open notepad on clicking but odbcad32 does not work - any ideas why?

CodePudding user response:

Based on one of my previous answers you could call the ODBC administrator like that

    Option Compare Database
    Option Explicit
    
    Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias _
                            "ShellExecuteA" (ByVal hwnd As LongPtr, _
                            ByVal lpOperation As String, _
                            ByVal lpFile As String, _
                            ByVal lpParameters As String, _
                            ByVal lpDirectory As String, _
                            ByVal nShowCmd As Long) As LongPtr
                            
    Private Declare PtrSafe Function Wow64EnableWow64FsRedirection _
                            Lib "kernel32.dll" (ByVal Enable As Boolean) As Boolean
   
    Private Sub RunODBC_on64Bit()
        Const SW_SHOWNORMAL = 1
        
        On Error Resume Next
        Wow64EnableWow64FsRedirection False
        ShellExecute 0, "open", "odbcad32.exe", "", "C:\windows\system32\odbcad32.exe", SW_SHOWNORMAL
        Wow64EnableWow64FsRedirection True
        
    End Sub

CodePudding user response:

I got it in the end - I replaced line

RetVal = Shell("odbcad32.exe", 1)

with

RetVal = Shell("Explorer.exe ""C:\Windows\SysWOW64\odbcad32.exe""", 1)

and that sorted it.

  • Related