title: finding latest file in a folder and opening it (vba access)
body: <p>I'm trying to open the latest file in a folder via button macro in access with the following code. </p>
  
  <p>Tested using the if statement and I didn't see any problems. But once I used do while, i receive an error message of run time 6, overflow. </p>
  
  <p>does <code>len(dir())</code> not work with loops?</p>
  
  <p>Below is my code.</p>
  
  <pre><code>Private Sub Command4_Click()
  Dim ~~~~ As Object
  Set ~~~~ = CreateObject("Excel.Application")
  Dim path As String
  Dim name As String
  Dim count As Long
  Dim number As Long
  
  
  path = "C:\Users\~~~~~\Desktop\~~~~~~~~~~~~\"
  number = Len(Dir(path &amp; "~~~~~~~ - " &amp; Format(Now() - count, "MMMM dd, yyyy") &amp; ".xlsm"))
  
  Do While number = 0
  count = count + 1
  Loop
  
  ~~~~~.workbooks.Open path &amp; "~~~~~~~ - " &amp; Format(Now() - count, "MMMM dd, yyyy") &amp; ".xlsm"
  
  
  End Sub
  </code></pre>
  
  <p>the ~ lines are just placeholders due to confidentiality.</p>
  
  <p>Thank you very much.</p>