Hi,
I currently have a functioning spreadsheet with VBA code that takes date from an existing database file somewhere else on the network and inserts it into my sheet as a pivot table. The code that identifies what filename to find is shown below:
Private Sub CommandButton2_Click()
'
' Month1 = Left(Format(DTPicker1.Value, "mm/dd/yyyy"), 2)
Month1 = Left(Format(Calendar1.Value, "mm/dd/yyyy"), 2)
' Year1 = Right(DTPicker1.Value, 4)
' Month1 = DTPicker1.Month
' Year1 = DTPicker1.Year
Year1 = Calendar1.Year
' DataFile = "" & Year1 & " " & Month1 & " 01 0000 (Wide)"
DataFile = "" & Year1 & Month1 & "~2"
The filename falls under a directory later identified in the code, but the filename representation is something like this:
2010 09 01 0000 (Wide).DBF
What I'd like to do is modify this code to obtain the previous month's data as well, but I struggle to understand how the code above works exactly. I've tried modifying the last two lines dozens ways with poor results. Specifically only the last line seems to matter when I change it, and I do not understand where the "~2" comes into play, is that some sort of wildcard?
I've tried replacing & Month1 & with & (Month1 - 1 ) & and it comes back and says "cannot find 20108~2", and even if I rename a file 20108 01 0000 (wide). It seems to change the formatting of the file its looking for whenever I introduce the formula, but even modifying the file name and playing around enough with the formula will not return the desired results. Also, I"ve tried placing the entire file name structure in the last line, similar to the 2nd to last line, but it returns with the message that it cannot find the file name "... [Wide]" instead of (Wide), and I cannot seem to find any way around the parenthesis turning into brackets.
I feel like i'm missing some fundamental issue here. Any guidance is appreciated, thanks.
Bookmarks