Check File date

InptTrdr

New Member
Joined
May 16, 2011
Messages
8
I have a macro that imports information for an Access file. What I am try to accomplish is when I run this macro to check if the Access file is as of yesterdays date. I've created the below, but it always runs as Moddate <> Testdate when I know it is not true. The other issue is, when the msgbox pops up and I say "yes" it will message is still gives "you said no." Any assistance would be appreciated.

Code:
Sub moddate1()
Dim Moddate As Date
Dim Testdate As Date
 
Moddate = Format(FileDateTime("C:\temp\Reports\report.mdb"), "mm/dd/yyyy")
Testdate = Format((Date - 1), "dd/mm/yyyy")
 
If Moddate <> Testdate And MsgBox("Report is out of date.  Continue?", vbYesNo) = vbYes Then
   MsgBox ("you said yes")
   Else
   MsgBox ("you said no")
   Exit Sub
End If
 
'rest of macro runs from here formating and such without problem.....
 
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Assuming the FileDateTime() functions works (I'm not familiar with that one), try this:
Code:
Sub moddate1()
Dim Moddate As Date
Dim Testdate As Date
Dim ans As Integer
 
Moddate = Format(FileDateTime("C:\temp\Reports\report.mdb"), "mm/dd/yyyy")
Testdate = Format((Date - 1), "dd/mm/yyyy")
 
If Moddate <> Testdate Then
    ans = MsgBox("Report is out of date.  Continue?", vbYesNo) Then
    If ans <> vbYes Then      
        Exit Sub
    End If   
End If
 
'rest of macro runs from here formating and such without problem.....
 
End Sub
 
Upvote 0
Xenou,

I'm getting an error, "Compile error: Syntax error" referencing the below:

Code:
ans = MsgBox("Report is out of date.  Continue?", vbYesNo) Then

I'm too much of a noob to figure out the correct syntax. Thanks for all your help.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,752
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top