I guess I'm getting old, but here is the fixed code:
VB Code:
  1. Public Class FrmSearchCorresp2
  2.         Inherits BeheerCDs.Form1
  3.         Private WithEvents dataGrid1 As DataGrid
  4.         Public DSExcel As New System.Data.DataSet
  5.         Public DataConnectionCorresp As OleDbConnection
  6.         Public Delegate Sub FillHandler(ByVal ds As DataSet)
  7.         Private distraction As FrmDistraction
  8.  
  9.  
  10.         Public Function GetSourcePath(ByVal number As String) As String
  11.             Dim FileName As String
  12.             'alle info bevindt zich in nummer.xls
  13.             FileName = "\\Epsilon2\vol3\dok\" & number & "\corresp\" & number & "Nummer.xls"
  14.             Return FileName
  15.         End Function
  16.  
  17.         'GetDataFromExcel creates a dataset from an excel file on the server in my company
  18.         Public Sub GetDataFromExcel(ByVal FileName As String, ByVal RangeName As String, ByVal ds As System.Data.DataSet)
  19.  
  20.             Dim SQLString As String
  21.             Dim hitword, firma, afzender, bestemmeling As Boolean
  22.  
  23.             If Me.TextBoxHitword.Text <> "" Then hitword = True Else hitword = False
  24.             If Me.TextBoxFirma.Text <> "" Then firma = True Else firma = False
  25.             If Me.TextBoxAfzender.Text <> "" Then afzender = True Else afzender = False
  26.             If Me.TextBoxBestemmeling.Text <> "" Then bestemmeling = True Else bestemmeling = False
  27.  
  28.             Try
  29.                 Dim strConn As String = _
  30.                 "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  31.                 "Data Source=" & FileName & "; Extended Properties=Excel 8.0;"
  32.  
  33.                 DataConnectionCorresp = New OleDbConnection(strConn)
  34.  
  35.                 DataConnectionCorresp.Open()
  36.  
  37.                 SQLString = "SELECT * FROM " & RangeName
  38.  
  39.                 If (hitword = True And firma = False And afzender = False And bestemmeling = False) Then
  40.                     SQLString = SQLString & " WHERE [korte inhoud] like '%" & Me.TextBoxHitword.Text & "%'"
  41.                     SQLString = SQLString & " OR Firma like '%" & Me.TextBoxHitword.Text & "%'"
  42.                     SQLString = SQLString & " OR Afzender like '%" & Me.TextBoxHitword.Text & "%'"
  43.                     SQLString = SQLString & " OR Bestemmeling like '%" & Me.TextBoxHitword.Text & "%'"
  44.                 ElseIf (hitword = True And firma = True And afzender = False And bestemmeling = False) Then
  45.                     SQLString = SQLString & " WHERE [korte inhoud] like '%" & Me.TextBoxHitword.Text & "%'"
  46.                     SQLString = SQLString & " AND (Firma like '%" & Me.TextBoxFirma.Text & "%'"
  47.                     SQLString = SQLString & " OR Afzender like '%" & Me.TextBoxHitword.Text & "%'"
  48.                     SQLString = SQLString & " OR Bestemmeling like '%" & Me.TextBoxHitword.Text & "%')"
  49.                 ElseIf (hitword = True And firma = True And afzender = True And bestemmeling = False) Then
  50.                     SQLString = SQLString & " WHERE [korte inhoud] like '%" & Me.TextBoxHitword.Text & "%'"
  51.                     SQLString = SQLString & " AND Firma like '%" & Me.TextBoxFirma.Text & "%'"
  52.                     SQLString = SQLString & " AND (Afzender like '%" & Me.TextBoxAfzender.Text & "%'"
  53.                     SQLString = SQLString & " OR Bestemmeling like '%" & Me.TextBoxHitword.Text & "%')"
  54.                 ElseIf (hitword = True And firma = True And afzender = False And bestemmeling = True) Then
  55.                     SQLString = SQLString & " WHERE [korte inhoud] like '%" & Me.TextBoxHitword.Text & "%'"
  56.                     SQLString = SQLString & " AND Firma like '%" & Me.TextBoxFirma.Text & "%'"
  57.                     SQLString = SQLString & " AND (Bestemmeling like '%" & Me.TextBoxBestemmeling.Text & "%'"
  58.                     SQLString = SQLString & " OR Afzender like '%" & Me.TextBoxHitword.Text & "%')"
  59.                 ElseIf (hitword = True And firma = True And afzender = True And bestemmeling = True) Then
  60.                     SQLString = SQLString & " WHERE [korte inhoud] like '%" & Me.TextBoxHitword.Text & "%'"
  61.                     SQLString = SQLString & " AND Firma like '%" & Me.TextBoxFirma.Text & "%'"
  62.                     SQLString = SQLString & " AND Afzender like '%" & Me.TextBoxAfzender.Text & "%'"
  63.                     SQLString = SQLString & " AND Bestemmeling like '%" & Me.TextBoxBestemmeling.Text & "%'"
  64.                 ElseIf (hitword = False And firma = True And afzender = False And bestemmeling = False) Then
  65.                     SQLString = SQLString & " WHERE Firma like '%" & Me.TextBoxFirma.Text & "%'"
  66.                 ElseIf (hitword = False And firma = False And afzender = True And bestemmeling = False) Then
  67.                     SQLString = SQLString & " WHERE Afzender like '%" & Me.TextBoxAfzender.Text & "%'"
  68.                 ElseIf (hitword = False And firma = False And afzender = False And bestemmeling = True) Then
  69.                     SQLString = SQLString & " WHERE Bestemmmeling like '%" & Me.TextBoxBestemmeling.Text & "%'"
  70.                 ElseIf (hitword = False And firma = True And afzender = True And bestemmeling = False) Then
  71.                     SQLString = SQLString & " WHERE Firma like '%" & Me.TextBoxFirma.Text & "%'"
  72.                     SQLString = SQLString & " AND Afzender like '%" & Me.TextBoxAfzender.Text & "%'"
  73.                 ElseIf (hitword = False And firma = True And afzender = False And bestemmeling = True) Then
  74.                     SQLString = SQLString & " WHERE Firma like '%" & Me.TextBoxFirma.Text & "%'"
  75.                     SQLString = SQLString & " AND Bestemmeling like '%" & Me.TextBoxBestemmeling.Text & "%'"
  76.                 ElseIf (hitword = False And firma = False And afzender = True And bestemmeling = False) Then
  77.                     SQLString = SQLString & " WHERE Afzender like '%" & Me.TextBoxAfzender.Text & "%'"
  78.                 ElseIf (hitword = False And firma = False And afzender = False And bestemmeling = True) Then
  79.                     SQLString = SQLString & " WHERE Bestemmeling like '%" & Me.TextBoxBestemmeling.Text & "%'"
  80.                 ElseIf (hitword = False And firma = True And afzender = True And bestemmeling = True) Then
  81.                     SQLString = SQLString & " WHERE Firma like '%" & Me.TextBoxFirma.Text & "%'"
  82.                     SQLString = SQLString & " AND Bestemmeling like '%" & Me.TextBoxBestemmeling.Text & "%'"
  83.                     SQLString = SQLString & " AND Afzender like '%" & Me.TextBoxAfzender.Text & "%'"
  84.                 End If
  85.  
  86.                 Dim SelectCommand As New OleDbCommand(SQLString, DataConnectionCorresp)
  87.                 Dim DAExcel As New OleDbDataAdapter
  88.                 DAExcel.SelectCommand = SelectCommand
  89.                 DAExcel.Fill(ds, "Excel")
  90.                 DataConnectionCorresp.Close()
  91.             Catch
  92.  
  93.             End Try
  94.         End Sub
  95.  
  96.         Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  97.             'DSExcel is a private variable declared
  98.             DSExcel.Clear()
  99.             'creation of an instance of the delegate
  100.             Dim del As New FillHandler(AddressOf FillDatasetThread)
  101.             'Can I use the DSExcel to pass as a variable?
  102.             del.BeginInvoke(DSExcel, AddressOf CallBack, DSExcel)
  103.             'show the distraction form
  104.             'the showing of the form is thread 1 (the synchronous operation)
  105.             distraction = New FrmDistraction
  106.             distraction.ShowDialog()
  107.  
  108.             'execution continues here when the dataset is filled and displayed
  109.         End Sub
  110.  
  111.         ' this method is the start of the second thread : the asynchronous operation.  Am I correct?
  112.         Public Sub BeginFill(ByVal ds As DataSet)
  113.             Dim filenameNummer As String = GetSourcePath(Me.TextBoxNummer.Text)
  114.  
  115.             'here there is something wrong: suppose the user inputs a filenamenummer that doesn't exists,
  116.             'then the msgbox appears after the distraction form opens.
  117.             'When is the delegate method returning a value?
  118.             If File.Exists(filenameNummer) = True Then
  119.                 GetDataFromExcel(GetSourcePath(Me.TextBoxNummer.Text), "[blad1$A3:F3000]", ds)
  120.             Else
  121.                 MsgBox("Dossier " & Me.TextBoxNummer.Text & " bestaat niet.  Gelieve een ander dossiernr. in te geven", MsgBoxStyle.Critical, "")
  122.             End If
  123.         End Sub
  124.  
  125.         ' this method is the end of the second thread : the asynchronous operation.  Am I correct?
  126.         Public Sub EndFill(ByVal ds As DataSet)
  127.             'close the distraction dialog
  128.             distraction.DialogResult = DialogResult.OK
  129.             'handle results
  130.             If ds.Tables(0).Rows.Count > 0 Then
  131.                 Me.createstyles()
  132.                 Me.dataGrid1.DataSource = ds
  133.                 Me.dataGrid1.DataMember = "Excel"
  134.             Else
  135.                 MsgBox("No results", MsgBoxStyle.Critical, "")
  136.             End If
  137.         End Sub
  138.  
  139.         'creation of the callback method
  140.         Public Sub CallBack(ByVal ar As IAsyncResult)
  141.             Dim DS As DataSet = CType(ar.AsyncState, DataSet)
  142.             Dim del As New FillHandler(AddressOf EndFill)
  143.             'marshal back to the UI thread with the results
  144.             Me.Invoke(del, New Object() {DS})
  145.         End Sub

The problem was that the callback method wasn't on the UI thread so it couldn't display the dataset. To solve it you just use Me.Invoke to marshal back to the UI thread.