title: Ms Access Get filename with wildcards or loop
body: <p>I am using MS Access Forms and I am trying to open a file but don't know how to open the file based knowing only part of the name. Example below works </p>
  
  <pre><code>Private Sub Open_Email_Click()
    On Error GoTo Err_cmdExplore_Click
    Dim x As Long
    Dim strFileName As String
    strFileName = "C:\data\office\policy num\20180926 S Sales 112.32.msg"
    strApp = """C:\Program Files\Microsoft Office\Office15\Outlook.exe"""
    If InStr(strFileName, " ") &gt; 0 Then strFileName = """" &amp; strFileName &amp; """"
    x = Shell(strApp &amp; " /f " &amp; strFileName)
  Exit_cmdExplore_Click:
    Exit Sub
  
  Err_cmdExplore_Click:
    MsgBox Err.Description
    Resume Exit_cmdExplore_Click
  End Sub
  </code></pre>
  
  <p>If I change the strFilename to being 
  <code>strFileName = "C:\data\" &amp; Me.Office &amp; "\" &amp; Me.nm &amp; " " &amp; Me.pol &amp; "\" &amp; "*"&amp; " S Sales " &amp; Me.amt &amp; "*" &amp; ".msg"</code>
  It includes the * rather than using it as a wildcard, the date/numbers can be anything or in another format but always eight numbers. I tried using a while loop on the numbers but I am not sure the best way of doing this sorry.</p>