title: How to create a ODBC connection to SQL Server?
body: <p>I try to use Access to call a stored procedure in SQL Server. But have trouble to build the 
  ODBC connection, I do not know am I missing something? Or just need do some set in sql site? </p>
  
  <p>I have a screen like this:</p>
  
  <p><img src="https://i.stack.imgur.com/X0Ptq.jpg" alt="enter image description here">   </p>
  
  <p>and code behind the OK button is this:</p>
  
  <pre><code>      Dim dbPUBS As dao.Database
        Dim tdfPUBS As dao.TableDef
        Dim qdfPUBS As dao.QueryDef
        Dim strMsg As String
        Dim strSQL As String
  
    ' Check for existence of Server, Database and User Name.
            ' If missing, inform user and exit.
  
               If IsNull(Me!txtServer) Then
          strMsg = "Enter name of your company's Server." &amp; _
              &amp; "(See your database administrator)"
          MsgBox strMsg, vbInformation, "Missing Data"
          Me!txtServer.SetFocus
      ElseIf IsNull(Me!txtDatabase) Then
          strMsg = "Enter name of database. (Example: xxxx)"
          MsgBox strMsg, vbInformation, "Missing Data"
          Me!txtDatabase.SetFocus
      ElseIf IsNull(Me!txtUID) Then
          strMsg = "Enter user login.  (Example: xx)" = ""
          MsgBox strMsg, vbInformation, "Missing Data"
          Me!txtDatabase.SetFocus
      Else
          strServer   = Me!txtServer
          strDatabase = Me!txtDatabase
          strUID      = Me!txtUID
          ' Password may be NULL, so provide for that possibility
          strPWD      = Nz(Me!txtPWD, "")
  
          ' Prepare connection string
          strConnect = "ODBC;DRIVER={SQL Server}" _
                  &amp; ";SERVER=" &amp; strServer _
                  &amp; ";DATABASE=" &amp; strDatabase _
                  &amp; ";UID=" &amp; strUID _
                  &amp; ";PWD=" &amp; strPWD &amp; ";"
      End If
  
  
              Private Function ValidateConnectString() As Boolean
             On Error Resume Next
  
              Err.Clear
              DoCmd.Hourglass True
  
         ' Assume success
  
         ValidateConnectString = True
  
  ' Create test Query and set properties
  
          Set qdfPUBS = dbPUBS.CreateQueryDef("")
           qdfPUBS.Connect = strConnect
          qdfPUBS.ReturnsRecords = False
          qdfPUBS.ODBCTimeout = 5
  
  ' Attempt to delete a record that doesn't exist
  
            qdfPUBS.SQL = "DELETE FROM Authors WHERE au_lname = 'Lesandrini'"
  
  ' Simply test one Pass Through query to see that previous
  ' connect string is still valid (server has not changed)
  
             qdfPUBS.Execute
  
  ' If there was an error, connection failed
  
            If Err.Number Then ValidateConnectString = False
  
            Set qdfPUBS = Nothing
            DoCmd.Hourglass False
  
  End Function
  </code></pre>