Visit our new web pagesWe have launched a new extended set of web pages at www.alvechurchdata.co.uk. These old pages will stay on the server because people still have links to them but they will not be updated. The new version of this page is at www.alvechurchdata.co.uk/hints-and-tips/accdatestamp.html. |
||
Home About us Development Training Support |
Creating a datestamp in AccessA file name based on the date it was created can be very useful for log files or backups. This VBA function will generate an eight-character filename from the year, month and day of the current date.
Public Function
MakeFileName()
' Description.......: Makes a file name from the date ' Accepts...........: Nothing ' Returns...........: A file name of the pattern 20051225 ' Major change list.: Dim strDay As String Dim strMonth As String Dim strYear As String '-- Generate a yyyymmdd date string strYear = CStr(Year(Date)) '-- Add leading zeroes if needed for month and day strMonth = CStr(Month(Date)) If Len (strMonth) = 1 Then strMonth = "0" & strMonth End If strDay = CStr(Day(Date)) If Len (strDay) = 1 Then Then strDay = "0" & strDay End If MakeFileName = strYear & strMonth & strDay End Function NotesThe function returns a string so it can be used directly whenever you want a name that can be easily recognised. For example to export the customer table into Excel;
DoCmd.TransferSpreadsheet acExport, 3, _
acSpreadsheetTypeExcel3, 'Customers', _ MakeFileName() & '.xls', True If you ran this code on Chrstmas Day it would save the data to '20051225.xls'. The filename is laid out in year, month, date order so that you can easily sort a collection of filenames chronologically. With a bit more work the function can be extended to include hours, minutes and seconds to give many unique names on the same day. This function was originally written in VBA in Access 97 but can be easily modified to run as in VBScript. |
Hints & tips
The textbox class in Visual FoxPro 9 has a new Autocomplete
property which shows the user the previous values that have
been entered in that textbox.
More...
|