title: Terminating Query If Not Connection
body: <p>I have a code that uploads data to a SQL server database, I am trying to add in an IF line of code saying if there is a connection then to continue, but if there is not a connection then to END. I am having a difficult time figuring out the wording and placement though. The beginning of the code that connects is:</p>
  
  <pre><code>Public Function Update()
  Dim cdb As DAO.Database, qdf As DAO.QueryDef
  
  Dim rs As DAO.Recordset
  
  Dim err As DAO.Error
  
  Const ConnectionString = _
          "ODBC;" &amp; _
              "Driver={SQL Server Native Client 10.0};" &amp; _
              "Server=SERV;" &amp; _
              "Database=DB;" &amp; _
              "UID=ID;" &amp; _
              "PWD=PWD;"
  Set cdb = CurrentDb
  Set qdf = cdb.CreateQueryDef("")
  
  Set rs = CurrentDb.OpenRecordset("CDData", dbOpenTable)
  
  qdf.Connect = ConnectionString
  
  Do While Not rs.EOF
  </code></pre>