title: MS Access Freezes Up After Text Import
body: <p>I have the following code to import a delimited file into an Access 2003 database:</p>
  
  <pre><code>Public Function importTextFile(sFile As String,  _
                                  sTable As String, _
                                  sSpecification As String)
  On Error GoTo importTextFile_EH
  
  ' Validate arguments to see if the objects exist; if not, give a message 
  ' and exit
  If Not FileExists(sFile) Then
      MsgBox "File " &amp; sFile &amp; " does not exist; import terminated.",  _
                                  vbCritical + vbOKOnly,  _
                                  "Error"
      Exit Function
  End If
  
  If Not TableExists(sTable) Then
      MsgBox "Table " &amp; sTable &amp; " does not exist; import terminated.",  _
                                  vbCritical + vbOKOnly,  _
                                  "Error"
      Exit Function
  End If
  
  If Not SpecExists(sSpecification) Then
      MsgBox "Import Specification " &amp; sSpecification &amp;  _
                                  " does not exist; import terminated.",  _
                                  vbCritical + vbOKOnly,  _
                                  "Error"
      Exit Function
  End If
  
  ' Display a warning to let the user cancel if this is run by mistake.
  If vbYes = MsgBox("WARNING: This will delete all data currently in " &amp;  _
                                  sTable &amp; "; do you wish to continue?",  _
                                  vbExclamation + vbYesNo,  _
                                  "Import Text File") Then
      DoCmd.Hourglass Yes
  
      ' Cleardown the data in the table.
      DoCmd.Echo Yes, "Deleting data in " &amp; sTable &amp; " table..."
      DoCmd.SetWarnings False
      DoCmd.RunSQL "DELETE " &amp; sTable &amp; ".* FROM " &amp; sTable &amp; ";"
      DoCmd.SetWarnings True
  
      ' Import the text file into the table. 
      DoCmd.TransferText acImportDelim, sSpecification, sTable, sFile
  
      DoCmd.Echo Yes, "Import complete"
      DoCmd.Hourglass No
  Else
      DoCmd.Echo Yes, "Import cancelled."
  End If
  Exit Function
  
  importTextFile_EH:
      Debug.Print Err.Number &amp; "-" &amp; Err.Description
  
  End Function
  </code></pre>
  
  <p>I can call this function from a Macro using <code>RunCode</code> with argument <code>Function Name</code> valued as </p>
  
  <pre><code>importTextFile (Application.CurrentProject.Path &amp; "\" &amp;  _
                                  "batch_results.txt",  _
                                  "BatchEngineResults", _
                                  "specResults") 
  </code></pre>
  
  <p>and it works fine. I can also call it from the Immediate window and it works without any problems.</p>
  
  <p>However, if I call the function from a form (from the <code>Click</code> event of a command button), then Access freezes up. It looks like the import completes (the Import progress bar in the Access Database window status bar shows the import running and finishing), but then Access becomes unresponsive, both the form and the Access database window. Task Manager doesn't indicate that Access is hung (the task status is "Running") and I can close Access via the Close button on the title bar. When I open the database again, my table has all the data from the text file, so the import did work.</p>
  
  <p>I've also tried calling the macro from the form, but get the same results.</p>
  
  <p>Anyone have any ideas?</p>
  
  <p><strong>UPDATE:</strong> I tried a call to MsgBox after I call the function:</p>
  
  <pre><code>importTextFile (Application.CurrentProject.Path &amp; "\" &amp;  _
                                  "batch_results.txt",  _
                                  "BatchEngineResults",  _
                                  "specResults") 
  MsgBox "After Import"
  </code></pre>
  
  <p>A message box appears, and is responsive. When I dismiss it, Access freezes up as before. Do you think this means I may have an issue somewhere else with the form, and not with this function?</p>