[RESOLVED] Database Backup FormatDateTime Issue
Hi Friends
My code works fine when I'm press Cmdbackup
the file generate like this "Saturday, October 10, 2015.mdb"
but i want to change the file name last line adding (hour ,minute,seconds) like that
"Saturday,October10,2015 10 20 58.mdb" <== Here (10 is Hour :20 is Minute and 58 is seconds )
or
Saturday_October_10_2015_10_20_58.mdb
Please help my issue , I hope our forum friends support my code ..
Thanks
Code:
Dim FileSystemObject As Object
Dim strfilename As String
Private Sub cmdBackup_Click()
On Error GoTo e
'set the copying functionality
strfilename = "" + txtPath.Text + "\" + txtFile.Text + ".mdb"
'Set the object contractions
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
'Copy the file according the path settings
FileSystemObject.CopyFile App.Path & "\database\dbp.mdb", strfilename
PrgBar.Visible = True
timPrgBar.Enabled = True
Exit Sub
e:
MsgBox "Invalid Path Setting, Please Try Again", vbCritical, "Invalid Path Setting!"
End Sub
Private Sub cmdclose_Click()
Unload Me
End Sub
Private Sub Dir_Change()
txtPath.Text = "" & Dir.Path
End Sub
Private Sub Drive_Change()
Dim d, fs As Object
'Set the constrctions to created objectes
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(fs.GetDriveName(Drive.Drive))
'Set the contents of the selected drives
If d.IsReady Then
Dir.Path = Drive.Drive
Dir.SetFocus
Else
MsgBox "The Drive Is Not Ready!", vbExclamation, "Drive Not Ready!"
End If
End Sub
Private Sub Form_Load()
'Display Today 's date
txtFile.Text = FormatDateTime(Now, vbLongDate)
End Sub
Private Sub timPrgBar_Timer()
Static iCnt As Integer
'Run the timer and check the condition
If iCnt <= 100 Then
PrgBar.Value = iCnt
iCnt = iCnt + 1
Else
MsgBox "The Backup Procedure Has Been Successfully Completed!", vbInformation, "Successful Backup Procedure!"
Drive.SetFocus
PrgBar.Visible = False
timPrgBar.Enabled = False
End If
End Sub
Eagerly waiting for the reply friends,
Thanks for the support advance :)
Re: Database Backup FormatDateTime Issue
Ok, let's go one step at a time for readability. I will show only the Date/Time formatting stuff. You decide how to handle your text controls, path and extension and format them to get the whole filename in the end.
Code:
Dim strFilename As String
strFilename = FormatDateTime(Now, vbLongDate)
strFilename = strFilename & Right$(Format(Now, "yyyy/MM/dd HH:mm:ss"), 9)
strFilename = Replace(strFilename, ",", "")
strFilename = Replace(strFilename, " ", "_")
strFilename = Replace(strFilename, ":", "_")
MsgBox strFilename
Re: Database Backup FormatDateTime Issue
Nothing to it really:
Code:
MsgBox Format$(Now(), "dddd_mmm_dd_yyyy_Hh_Nn_Ss"".mdb""")
Nothing like Reading That Fine Manual.
Re: Database Backup FormatDateTime Issue
Hearty thank you for the solution (Reputation added)
Code:
strfilename = FormatDateTime(Now, vbLongDate)
strfilename = strfilename & Right$(Format(Now, "yyyy/MM/dd HH:mm:ss"), 9)
strfilename = Replace(strfilename, ",", "")
strfilename = Replace(strfilename, " ", "_")
strfilename = Replace(strfilename, ":", "_")
txtFile.Text = strfilename
Code exactly working , thanks again
Re: Database Backup FormatDateTime Issue
"dilettante" Thanks for the support (Reputation added)
your code works fine , thanks
Re: Database Backup FormatDateTime Issue
Great, glad it does what you need. You might marked the thread resolved (see "Thread tools" dropdown near the top of the page).