I have been figuring out how to link my SQL Server back end tables to my Access front end using VBA (not via DSN). I think I worked all of that out in the following post:
https://answers.microsoft.com/en-us/msoffice/forum/msoffice\_access-mso\_winother/how-to-connect-access-front-end-to-sql-server/fe7ff42a-f21d-4ffa-bf1a-bb961064f575
I have it up and running, and it works great. I'm just thinking through how to handle some errors, and have worked through a lot of that. But one that I haven't figured out how to handle is if the SQL Server connection fails. When I test this (by putting
in an incorrect password),

And then, it dumps them out into a dialog box where they can try new passwords!

I don't like this at all! How can I suppress these dialog boxes?! I already have error handling defined and SetWarnings = False. My full code (simplified/censored for posting) is as follows:
Public Function CreateSQLLinkedTable(strSourceTableName As String, strNewTableName As String) As Boolean
On Error GoTo OnError
Dim tdf As TableDef
Dim strConnect As String, strMsg As String
Dim fRetval As Boolean
Dim myDB As Database
' turn system warnings off
DoCmd.SetWarnings False
' set database vars
Set myDB = CurrentDb
Set tdf = myDB.CreateTableDef(strNewTableName)
' define connect string and source table
With tdf
.Connect = "ODBC;Driver={SQL Server};server=MyServer;database=MyDatabase;uid=MyUserID;Pwd=MyPassword;"
.SourceTableName = strSourceTableName
End With
' execute appending the table
myDB.TableDefs.Append tdf
' set bool var to True
fRetval = True
' turn system warnings back on
DoCmd.SetWarnings True
ExitProgram:
' this block of code will run if there are no errors
' set the return value = to fRetval (which was set to True above)
CreateSQLLinkedTable = fRetval
Exit Function
OnError:
MsgBox "There was an error connecting to the SQL Server data source. Error = " & Err & ", Description: " & Err.Description
'exit
Call CloseFormsAndQuit
End Function
Thanks!
Emily