title: Unrecognized DB Format-Excel VBA to Access Database
body: <p>Im using a .accdb file and connecting with the following code, which has worked for me multiple times, so I don't know why its corrupting the file this time.</p>
  
  <pre><code>dbPath = ActiveWorkbook.Path &amp; "\WaitAnalysisDB.accdb"
  tblName = "Wait_Data_Table"
  strcon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" &amp; dbPath &amp; "';"
  conn.Open strcon
  </code></pre>
  
  <p>Does the "Unrecognized Format" Access error only occur due to an error in the connection string, or could it be my SQL statement inserting records as well? Thanks</p>
  
  <p><br>
  <br></p>
  
  <p>Here's my code, if anyone cares to look through it. In the for loops that build the SQL statemetn (rcdDetail variable), I have an if statement, which basically says if there is a blank in Column A, then use the row above it that isnt blank. </p>
  
  <pre><code>Dim conn As New ADODB.Connection, rs As New ADODB.Recordset, dbPath As String, tblName As String
  Dim rngColHeads As Range, rngTblRcds As Range, colHead As String, rcdDetail As String
  Dim ch As Integer, cl As Integer, notNull As Boolean, strcon As String, lr As Integer
  Dim currentdate As String
  Dim strdbcheck As String
  
  
  'Code Checks if There Are Records for the Date in the DB
  'If there is, then it skips the SQL code
  
  currentdate = Date
  dbPath = ActiveWorkbook.Path &amp; "\WaitAnalysisDB.accdb"
  tblName = "Wait_Data_Table"
  strcon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" &amp; dbPath &amp; "';"
  conn.Open strcon
  
  strdbcheck = "SELECT * FROM " &amp; tblName
  rs.Open strdbcheck, conn
  
  rs.Filter = "Date= #" &amp; currentdate &amp; "#"
  If Not rs.EOF Then
      Set rs = Nothing
      Set conn = Nothing
      GoTo SkipExport
  Else
      Set rs = Nothing
      Set conn = Nothing
          GoTo Export
  End If
  
  
  
  Export:
  
  'Set Up Connections
  dbPath = ActiveWorkbook.Path &amp; "\WaitAnalysisDB.accdb"
  tblName = "Wait_Data_Table"
  
  'Create Date Column
  Worksheets("Wait Analysis DATA").Select
  lr = Cells(Rows.Count, "K").End(xlUp).Row
  currentdate = Date: Range("O1").Value = "Date": Range(Range("O2"), Range("O" &amp; lr)).Value = currentdate
  
  Set rngColHeads = ActiveSheet.Range(Range("a1"), Range("a1").End(xlToRight))
  Set rngTblRcds = ActiveSheet.Range(Range("K2:k" &amp; lr).Offset(0, -10), Range("K2:k" &amp; lr).Offset(0, 4))
  
  'SQL connection String
  strcon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" &amp; dbPath &amp; "';"
  
  'Create String for Columns for SQL
  colHead = "(["
  For ch = 1 To rngColHeads.Count
      colHead = colHead &amp; rngColHeads.Columns(ch).Value
      Select Case ch
          Case Is = rngColHeads.Count
              colHead = colHead &amp; "])"
          Case Else
              colHead = colHead &amp; "],["
      End Select
  Next ch
  
  
  On Error GoTo EndUpdate
  conn.Open strcon
  conn.BeginTrans
  
  Dim tempcl As Integer
  
  For cl = 1 To rngTblRcds.Rows.Count
  
      If Range("a2").Offset(cl - 1, 0) = "" Then
          tempcl = cl - Range("a2").Offset(cl, 0).End(xlUp).Rows.Count
  
          notNull = False
          rcdDetail = "('"
          For ch = 1 To rngColHeads.Count
          Select Case rngTblRcds.Rows(tempcl).Columns(ch).Value
              Case Is = Empty
                  Select Case ch
                      Case Is = rngColHeads.Count
                          rcdDetail = Left(rcdDetail, Len(rcdDetail) - 1) &amp; "NULL)"
                      Case Else
                          rcdDetail = Left(rcdDetail, Len(rcdDetail) - 1) &amp; "NULL,'"
                  End Select
              Case Else
                  notNull = True
                  Select Case ch
                      Case "11":
                          rcdDetail = rcdDetail &amp; rngTblRcds.Rows(cl).Columns(ch).Value &amp; "','"
                      Case Is = rngColHeads.Count
                          rcdDetail = rcdDetail &amp; rngTblRcds.Rows(tempcl).Columns(ch).Value &amp; "')"
                      Case Else
                          rcdDetail = rcdDetail &amp; rngTblRcds.Rows(tempcl).Columns(ch).Value &amp; "','"
                  End Select
              End Select
      Next ch
          tempcl = 0
          GoTo skipads
  
      End If
  
  
      notNull = False
      rcdDetail = "('"
      For ch = 1 To rngColHeads.Count
          Select Case rngTblRcds.Rows(cl).Columns(ch).Value
              Case Is = Empty
                  Select Case ch
                      Case Is = rngColHeads.Count
                          rcdDetail = Left(rcdDetail, Len(rcdDetail) - 1) &amp; "NULL)"
                      Case Else
                          rcdDetail = Left(rcdDetail, Len(rcdDetail) - 1) &amp; "NULL,'"
                  End Select
              Case Else
                  notNull = True
                  Select Case ch
                      Case Is = rngColHeads.Count
                          rcdDetail = rcdDetail &amp; rngTblRcds.Rows(cl).Columns(ch).Value &amp; "')"
                      Case Else
                          rcdDetail = rcdDetail &amp; rngTblRcds.Rows(cl).Columns(ch).Value &amp; "','"
                  End Select
              End Select
      Next ch
  
  skipads:
      Select Case notNull
          Case Is = True
              rs.Open "INSERT INTO " &amp; tblName &amp; colHead &amp; " VALUES " &amp; rcdDetail, conn
          Case Is = False
                  'do not insert record
      End Select
  
  
  Next cl
  
  EndUpdate:
      If Err.Number &lt;&gt; 0 Then
          On Error Resume Next
          conn.RollbackTrans
          MsgBox "There was an error. This will exit the macro.", vbCritical, "Error!"
          End
      Else
          On Error Resume Next
          conn.CommitTrans
      End If
  
      conn.Close
      Set rs = Nothing
      Set conn = Nothing
      On Error GoTo 0
  
  
  
  SkipExport:
  </code></pre>