Introduction
If your Database is installed on a Local Area Network (LAN) location, then a regular server backup is done on a Daily/Weekly/Monthly/Quarterly basis by the Network Team and kept them in Fire-proof Cabinets away from the Computer Center. If something happens to your database, like database corruption or being deleted by mistake, etc., you can always send a request to the Computer Department giving details of location, database name, and safe backup date from which you would like to restore. This may take a few hours to a few days to get done because the backup tapes or other mediums must be transported back from their storage location before they are able to complete your request.
If your project has its own backup procedure and does it on a regular basis, then you don't have to go after centralized Network backups, causing delays in restoring the Database. This will also ensure that your Application's downtime is very minimal.
You can secure the Database Objects (Forms, Queries, Tables, Reports, etc.) from within the Database but when it comes to the safety of the Database File this will not work. When the database is on a Network location several Users can have access rights to that folder, besides your Application Users, and the database is not safe there.
You cannot make a Database Read-Only under Network Security to protect it from inadvertent loss. If you do that then you cannot work with the Database.
Automatic Daily Backup
As a precautionary measure, we can take a quick Daily Backup of the Database File, from Server to Local Disk, or vice versa with a DOS Batch File. The Backup should run immediately on opening the Database for the first time of the day, by any one of the users.
We can do this with a simple VBA Routine to create a DOS Batch File in the database folder and run it from there to make a copy to the local drive. We need a small table with a single record to keep track of the Backup event. The backup program should run only once a day when the database is open for the first time on the day, by any one of the users and should prevent the program from running on subsequent shutdowns and re-opening events.
Preparations
- Create a Table with the following structure and save it with the name Bkup_Ctrl and add a single record with a date earlier than today in the bkupdate Field. Leave the other field blank.
Table : Bkup_Ctrl Structure Srl. Field Name Type Size 1. bkupdate Date/Time 2. workstation Text 20 Table : Bkup_Ctrl bkupdate workstation 01/05/2008 PC1-1234 Copy and Paste the following Code into a Global Module of your Project and save the Module.
Public Function SysBackup() '------------------------------------------------------' 'Author: a.p.r. pillai 'Date : 01-Apr-2008 'URL : http://www.msaccesstips.com 'All Rights Resersed by msaccesstips.com '------------------------------------------------------ Dim dbPathName, j As Long, t As Date Dim bkupdate, strBatchFlle As String, qot As String On Error GoTo sysBackup_Err qot = Chr$(34) bkupdate = Nz(DLookup("bkupdate", "Bkup_ctrl"), 0) ' bkupdate+7 > date() for weekly backup If bkupdate = Date Or bkupdate = 0 Then Exit Function End If dbPathName = CurrentDb.Name 'dbPathName = "\\ServerName\Accounts\MIS\MISDB.Accdb" 'If BE on LAN Server j = InStrRev(dbPathName, "\ ") If j > 0 Then strBatchFlle = Left(dbPathName, j) strBatchFile = strBatchFlle & "bakup.bat" Open strBatchFile For Output As #1 Print #1, "@Echo off" Print #1, "Echo :------------------------- " Print #1, "Echo : " & dbPathName Print #1, "Echo Daily Backup to C:\ " Print #1, "Echo :------------------------- " Print #1, "Echo : " Print #1, "Echo :Please wait... " Print #1, "Echo : " Print #1, "Copy " & qot & dbPathName & qot & " " & qot & "C:\ " & qot 'add lines here for Back-end database or for other Files Close #1 'Copy file Call Shell(strBatchFile, vbNormalFocus) t = Timer Do While Timer <= t + 10 'increase for bigger database DoEvents 'wait for 10 seconds to complete the process Loop DoCmd.SetWarnings False DoCmd.RunSQL "UPDATE Bkup_Ctrl SET Bkup_Ctrl.bkupdate = Date(), Bkup_Ctrl.workstation = Environ('COMPUTERNAME');" DoCmd.SetWarnings True 'Kill strBatchFile End If sysBackup_Exit: Exit Function sysBackup_Err: MsgBox Err.Description, , "sysBackup()" Resume sysBackup_Exit End Function
- Add the following line of code in the On_Load() Event Procedure of the Startup Screen or Main Switchboard or any other form that opens immediately after loading the Database.
SysBackup
How does it Work?
At the beginning of the SysBackup() routine, the Program reads the last backup date from the Bkup_Ctrl Table and checks whether it matches today's date, if it does then stops the program from proceeding further. By replacing the expression bkupdate = date() with the expression bkupdate+7 > date() you can schedule the Backup to run at weekly intervals on a particular Day of the Week.
The VBA Routine creates a DOS Batch File in the same folder of your Database and Runs it. The DOS Copy command is used for copying the Database File to the User's local drive. Even though a VBA FileCopy() Function is available, this will not work from within to make a copy of the same Database.
You may modify the line to change the Target Location C:\ to a different one if needed.
A delay loop is built into the routine to slow down the program for about 10 seconds, to give enough time for the DOS Command to complete copying the Database. Normally, the VBA Code execution will not wait for the DOS Command to complete before executing the next statement. This will also prevent the User from starting to work with the Database before the copy operation is complete. You may increase or decrease this value depending on the size of the Database, or after trial runs of the procedure to determine the approximate time it takes to copy.
The control table's bkupdate Field is updated with the current date immediately after completion of the Copy operation and this will prevent further running of this procedure in subsequent Sessions on the same day. If your Application has a Back-End Database then install this table in there and link it to the Front-End. If your Application is on a Network and shared by several Users then by referring to the workstation field you can easily find out which machine has the latest Backup Copy.
The Kill strBatchFile statement (if enabled) will delete the DOS Batch File after the backup operation. The delay loop protects the DOS Batch File from this statement for about 10 seconds. Enable this line if you don't want the batch file to remain in the database folder.
Create Batch File Manually.
You can create a DOS Batch file manually, with a Text Editor like Windows Notepad, install it in the Database folder and run it from the Code or Macro. You may define the Source, and Target Locations manually for the Copy command.
Portability Considerations
The advantage of the above Code is portability and convenience. You can copy the Code and the bkup_ctrl Table into your other Projects and run it without much change or worrying about the Source or Target Location addresses of the Database.
Download
Download Demo DailyBakup
I'm facing the below error:
ReplyDelete((Path/File access error))
((OS Warpping rule MOR-3-1
MSOffice_File_Write has blocked C:\Program File\Microsoft Office\Office\MSACCESS.EXE trying to access K:\ES\bakup.bat))
I know that it related some security settings, could you please help?
Thanks,
Nadia
Which Version of Windows you are using. We have Windows2000 installations on Workstations and WindowsNT on Network and Batch Files run without problem.
ReplyDeleteAsk your System Administrator to Join you temporarily as your Workstation Administrator and try running the backup procedure. Batch Files comes under the Category of Program Files (.exe).
It should work even with Normal security policy on Workstation.
Regards,
Hi,
ReplyDeleteI would like to use this to do a daily backup to a subfolder and need to add the date to the name of the file - and cant get around the default date format that uses forward slashes (mm/dd/yyyy = illegal ). Can you help?
Open strBatchFile For Output As #1
Print #1, "@Echo off"
Print #1, "Echo :Today is " & Date
Print #1, "Echo : "
Print #1, "Echo :------------------------- "
Print #1, "Echo :File being backed up is " & dbPathName
Print #1, "Echo : Daily Backup to C:\testDB\backups"
Print #1, "Echo :------------------------- "
Print #1, "Echo : "
Print #1, "Echo : Please wait... "
Print #1, "Echo : "
Print #1, "Copy " & qot & dbPathName & qot & " " & qot & "C:\testDB\backups" & qot
Print #1, "Pause"
'add lines here for Back-end database or for other Files
Close #1
Add one more Variable in the declaration at the beginning of the routine
ReplyDeletedim target
before the Open statement write the following:
target = dir(dbPathName)
target = left(target,len(target)-4) & format(date(),"mm-dd-yyyy") & ".mdb"
rewrite the following statement:
Print #1, "Copy " & qot & dbPathName & qot & " " & qot & "C:\testDB\backups\" & target & qot
hello dear Mr.
ReplyDeleteHow are u
thanks for your helping
i did all of mention sections but it is not working for me
1- I made a above table : Question : what is "Srl." name in table ?
2- I did copy above code in Module name is "Module"
3- I have a 2 bootable form "Autorun" that Run in same time at first open and i Did Create a "SysBackup" in Open Event and set this "Call SysBackup" like this
Private Sub Form_Load()
Call SysBackup
End Sub
So a Hope to work it for me "Daily Backup"
But form 2 days ago to now it is not making any backup
Please Help me
Note : i want , it work backup in this location : \\Servername\folder\ With This name : Databasename_Date()format
Thanks for you help
Best Regards
Helpppppppppppppppppppppppppppppppp
Hi,
ReplyDeleteYou can ignore the "Srl." Column while creating the Table. This was only to indicate the number of fields required in the Table. You can see in the next image with the data shows only bkupdate and workstation fields.
I assume that you have copied the main Code into a Standard Module and not in the Form Module.
You may create a small database and import the Form that calls the SysBackup() Program, the main Program that you have copied and pasted from this page and the Backup control table.
Use Winzip and zip the database along with the Backup Batch File and email to me: aprpillai48@gmail.com.
Let me have a look at your problem, correct them if necessary and send it back to you in no time.
Regards,
Hi dear again
ReplyDeleteYou are very kind for me but this is part of a domain location
thant i have an admin of it
you said i should copy the main Module to my Bootable form ?????
I did copy it on the Main Module and Call it from the Bootable form .
Ok i try agian with this method and call back
thanks for your Informations
Regards
Kiss
I have a more Question Please See .
ReplyDeleteI have a code to for a command for backup
this is code :
I did it Too , check mark 'Microsoft Scripting Runtime' for the CopyFile piece to work!
But it is not work
it is an error in fso.CopyFile Line
I don't undrestand it
Private Sub BackupCopy_Click()
'This function will allow you to copy a db that is open,
Dim fso As FileSystemObject
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
sSourcePath = "D:\Access\Mainta Database"
sSourceFile = "Mainta.mdb"
sBackupPath = "D:\Access\Mainta Database\Bck"
sBackupFile = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".mdb"
Set fso = New FileSystemObject
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & sBackupPath & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & sBackupFile, vbInformation, "Backup Completed"
End Sub
in the form Load i did this
ReplyDeleteBut it has an error in this line strBatchFile = strBatchFlle & "bakup.bat"
Private Sub Form_Load()
'------------------------------------------------------
'Author: a.p.r. pillai
'Date : 01-Apr-2008
'URL : http://www.msaccesstips.com
'All Rights Resersed by msaccesstips.com
Dim dbPathName, j As Long, t As Date
Dim bkupdate, strBatchFlle As String, qot As String
On Error GoTo sysBackup_Err
qot = Chr$(34)
bkupdate = Nz(DLookup("bkupdate", "Bkup_ctrl"), 0)
' bkupdate+7 > date() for weekly backup
If bkupdate = Date Or bkupdate = 0 Then
Exit Sub
End If
dbPathName = CurrentDb.Name
j = InStrRev(dbPathName, "\ ")
If j > 0 Then
strBatchFlle = Left(dbPathName, j)
strBatchFile = strBatchFlle & "bakup.bat"
Open strBatchFile For Output As #1
Print #1, "@Echo off"
Print #1, "Echo :------------------------- "
Print #1, "Echo : " & dbPathName
Print #1, "Echo :Daily Backup to \\Mainta-sql\Mainta\BackupDaily\ "
Print #1, "Echo :------------------------- "
Print #1, "Echo : "
Print #1, "Echo :Please wait... "
Print #1, "Echo : "
Print #1, "Copy " & qot & dbPathName & qot & " " & qot & "\\Mainta-sql\Mainta\BackupDaily\ " & qot
'add lines here for Back-end database or for other Files
Close #1
'Copy file
Call Shell(strBatchFile, vbNormalFocus)
t = Timer
Do While Timer <= t + 10
DoEvents 'wait for 10 seconds
Loop
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE Bkup_Ctrl SET Bkup_Ctrl.bkupdate = Date(), Bkup_Ctrl.workstation = Environ('COMPUTERNAME');"
DoCmd.SetWarnings True
'KillstrBatchFile
End If
sysBackup_Exit:
Exit Sub
sysBackup_Err:
MsgBox Err.Description, , "sysBackup()"
Resume sysBackup_Exit
End Function
Sory again in your code you used of " strBatchFlle "
ReplyDeleteis this true ???????
See strBatchFlle or strBatchFile ???? which one ? is currect
This may not work from within the database. Make few changes in the following lines of your code and try again. Add a backslash at the end of the first and third line as I have shown below and retry it.
ReplyDeletesSourcePath = D:\Access\Mainta Database\
sSourceFile = Mainta.mdb
sBackupPath = D:\Access\Mainta Database\Bck\
sBackupFile = BackupDB_ & Format(Date, mmddyyyy) & _ & Format(Time, hhmmss) & .mdb
Set fso = New FileSystemObject
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing
Regards,
strBatchFile variable have the Location Address of the Batch File: bkup.bat. This file must be in the same location of the Database. The Main Program you must save in the Standard Module not in the Form Module.
ReplyDeleteok how can i refer it with "Call" ?
ReplyDeleteIn above you said
""""
3.Add the following line of Code in the On_Load() Event Procedure of the Startup Screen or Main Switchboard or any other Form that opens immediately after loading the Database.
SysBackup """" How ??????
You can call the program as below:
ReplyDeleteCall Sysbackup()
sory dear friend in first may i chat with you in google ?
ReplyDeletei sent an invate to you ......
I have a question
i want send first page of report to one report and
2nd to end pages to another report
how can i do that ?
thanks
and one more question :
i have a database on server , i want to allow some of users to read and some of others write database
in location i did security for domain mention users but
who has allow to write in server folder , can delete database
how can i security more that user could n't delete source but can wirte in database table ?????
thanks more
A. First on the Report issue:
ReplyDeleteYou cannot split the same Report in two unless you export the Report into PDF Format (If you have Adobe PDF Writer installed) and split the pages through Documents Menu Options.
If you are organizing your Report-Data in a certain order using Queries then you can solve your problem with two copies of the same Query(with different names: say Query1 and Query2) and two copies of the same Report (say Report1 and Report2).
Query1-SQL :
SELECT TOP 50 Employees.*
FROM Employees
ORDER BY Employees.EmployeeID;
Design Report1 on this Query to Print the first 50 Employees List on the first page of the Report.
Query 2 SQL :
SELECT Employees.*
FROM Employees
WHERE (((Employees.EmployeeID) Not In (select EmployeeID from Query24)))
ORDER BY Employees.EmployeeID;
In Query2 we are using Query1 Employee Codes as criteria to exclude them from Report2.
You can design two different Reports on both Queries and sent to different destinations.
Instead of the sample number 50, which I have used in the above example you may select a convenient number to fit on the first page of your Report depending on the design of your Reports.
B. Server side access rights are enforced by Network Administrators. If the database is read only then users cannot write anything into it and save it. Access rights on individual database objects are implemented in the same way assigned on individual files on Server.
Normally the Network Server is backed-up on daily, Weekly, Monthly basis by the Network Backup Operators. If your database is lost you can ask the Network Administrators to restore from the latest Backups. It is better if you implement a daily backup method as explained in my Article:Database Daily Backup
Regards,
hi dear friend
ReplyDeletethanks for your help
I accidently foun this code, which is very neat but I am having problems getting it to work it, as it is displaying error "File Not Found". Any ideas?
ReplyDeleteCheck whether the Batch File is present in the Database location.
ReplyDeleteHi, thanks for the reply
ReplyDeleteManaged to workout the problem. There was a end if missing, and also had to remove the spaces in the path from your code example. Am just wondering will this always overwrite the previous backup version?
Thanks
Yes, it will overwrite the file every time.
ReplyDeletehi again how are u
ReplyDeleteMay you take a template of this backup ( sample database) for download here ???
we need to see in sample how you did
Best regards
You may download a Demo database from this Link: http://www.msaccesstips.com/downloads/2008/05/daily-backup.shtml
ReplyDeletehi there
ReplyDeletehow are you today
i did download your Demo and run it.
back up ok in your file but have this problem error "Undefined function 'Environ' in expression "
But in My database on startup this Code , have an error in 'j'
it said , varibale not defined
Private Sub Form_Timer()
j = j + 1
If j > 2 Then
Me.TimerInterval = 0
SysBackup
End If
End Sub
please help
You must add a line Dim J at the top of the Form Code Module below the line Option Compare Database as shown below:
ReplyDeleteOption Compare Database
Dim j
to correct the 'variable not defined' Error.
You must attach the Library File: Microsoft Visual Basic for Applications Extensibility 5.3 to your Database to rectify the Undefined 'Environ()' Function Error. Do the following:
1. Display the Visual Basic Editing window (Alt+F11).
2. Select References from Tools Menu.
3. Look for the name Microsoft Visual Basic for Applications Extensibility 5.3 and put a check mark to select it.
4. Click OK to complete.
Regards,
thanks it is ok
ReplyDeletei have more question master please .............LOL
think we have a report , and we want fix 10 or more row in report
therefor if data of some range has 2 row , we could see 8 row blank fixed in below of it .... clear i say , we want see always 10 row record , HOWEVER it is blank like excel ....
could we do ???
example : report has signing row in below and we must have 10 row in report and signing row in below of them .
thanks
sory you didnt say about this error i said
ReplyDeleteUndefined function Environ in expression
one question :
ReplyDeleteevery open database it is run , what matter ???
only if date is today code is stop but if you change date of bkupdate table is yesterday , the code is run evey each open ???
Yes, already did mention about the 'Environ' Error. You can correct that error by attaching the Library File: 'Microsoft Visual Basic for Applications Extensibility 5.3' to your database. The procedure is explained earlier, please refer my earlier reply.
ReplyDeleteThe Daily backup will run only once when you open the database for the first time during the day. Today's date is updated in the parameter table after the backup. This will prevent taking backups every time you open the database during the day.
ReplyDeleteRegarding the Question of 10 lines Report, I think with few blank records in a Table, with the same structure of your Report Query, and a Union Query with the control of a VBA Program we can create your Report the way you want. Copy the Table,Query and Report into a separate database, Zip the database with Winzip and forward it to me by mail : aprpillai@msaccesstips.com
ReplyDeletehi dear friend
ReplyDeleteat first do you have yahoo messenge ID or Gmail ID for Chat ?
I have a problem and i hope you could help me .
in my access database , i have a form named "ReportDateRange" and it has 2 box , "Start Date " and "Finish Date" , all of my report did set to this Date Range , i did set those boxes to Date() by Default , but at first boot , i have to open and save mention form to work .
could i find a way that without open it , to set date Rage
Note : this way could help the users for setting once date range for all report....
Beacuse of this problem i have to open mention form via Autoexec at first open of Main form at the same time ...
thanks Before
Please send me e-mail to: aprpillai@msaccesstips.com explaining your issues.
ReplyDeleteRegards,
It is better if you create a Parameter Form linked to a Table with two fields: StartDate and EndDate with only one record in the Table. You may create Option Group control on this Form to run different Reports using the StartDate and EndDate Field Values as criteria parameter.
ReplyDeleteOnce you set the date values into the Table Fields through the Parameter Form it will remain intact for all your purposes till you change it.
Regards,
hi dear friend
ReplyDeletei hope you have a good day today
this solution is good but i made my all report by setting this parameter and if i want to change it , it is very hard to find all records to change ....
so , if i could Run this form , mention form i mean from start , if i could to open automaticaly and push save automaticaly with vb code it will be solved , this is My form code ......
i have a command button in this form with Preview named contain this code on it
Private Sub Preview_Click()
If IsNull([Beginning Entry Date]) Or IsNull([Ending Entry Date]) Then
MsgBox "You must enter both beginning and ending dates."
DoCmd.GoToControl "Beginning Entry Date"
Else
If [Beginning Entry Date] > [Ending Entry Date] Then
MsgBox "Please Retype Finish Date : Must be Greater or Equal Than Current Date"
DoCmd.GoToControl "Beginning Entry Date"
Else
Me.Visible = False
End If
End If
End Sub
i did call this function with this sample
Call Preview_Click
but is not working
do u know any solution ??? for run this command via autoexec macro?
thanks
You can write the Code in a Standard Module as a Public Function and call it from the Command Button Click Event Procedure with the Form name as Parameter. You may Copy and Paste the following Code into a Standard Module:
ReplyDeletePublic Function Pre_view(ByVal strfrm As String)
Dim frm As Form
Set frm = Forms(strfrm)
If IsNull(frm![Beginning Entry Date]) Or IsNull(frm![Ending Entry Date]) Then
MsgBox "You must enter both beginning and ending dates."
DoCmd.GoToControl "Beginning Entry Date"
Else
If [frm]![Beginning Entry Date] > frm![Ending Entry Date] Then
MsgBox "Please Retype Finish Date : Must be Greater or Equal Than Current Date"
DoCmd.GoToControl "Beginning Entry Date"
Else
frm.Visible = False
End If
End If
End Function
Write the following Code into the Command Button Click Event Procedure:
Private Sub Preview_Click()
Pre_view Me.Name
End Sub
You can use the Autoexec Macro to Open the Form on startup.
hi dear friend
ReplyDeletei did this solution before but i did again same you said
after i create on top codes
i did add open the mention form in startup and add this line to below of it
RunCode ..... Pre_view
But it has an error to startup the form via macro general error
it cannot be run via Autoexec
thansk Before
in your Code ... , What is "strfrm" ???
ReplyDeletei want to RunCode this Command via Startup what Could i must to do ??
and what is "Me.Name" ??
ReplyDeleteMe represents the active Form. Active Form Name is passed to the Program as parameter. You can pass the name of the active Form in quotes like Pre_View "myForm" while calling a Program from within the Form VBA Module. If your form's name is myForm.
ReplyDeleteWhen you attempt to Run Pre_View() Program from Macro; the Form is not open to validate the Field Values in the Program. That is why the Program is showing error. The Form must be already in open state before we run the program.
ReplyDeleteCreate a Macro with the name Autoexec to open your form as soon as you open the Database (with OpenForm Action and type the Form's name in the Form Name Property and save the macro.
Copy and Paste the following lines of Code into the VBA Module of the Form:
Private Sub Form_Load()
Pre_view Me.Name
End Sub
strfrm is a Variable defined in the Program as parameter to receive the Form's Name into the Program so that we can use it to refer to the controls (like Beginning Entry date to validate its contents.
ReplyDeleteWhen we call the Program like Pre_View "myForm" the form name myForm will be passed into the Variable strfrm in the main program and we use that information for further actions. I hope it is clear now.
well written blog. Im glad that I could find more info on this. thanks
ReplyDeletePrivate Sub cmd1_Click()
ReplyDeleteDim str As String
Dim I As Integer
I = w1dia
If rs.State = 1 Then rs.Close
str = "Select * from AXLEMASTERS where W1Dia" ' w1dia Then
rs.Find "W1Dia = " & Txt1.Text
If rs.EOF Then
cr1.ReportFileName = App.Path & "\lowdia.rpt"
cr1.DataFiles(0) = App.Path & "\LocoShed.mdb"
cr1.Action = 1
Else
Do Until rs.EOF
MsgBox "Record not found"
rs.MoveNext
Loop
End If
End If
End Sub
the above said coding used but i unable to receive the below or less than data on report please any one help me
I presume that you have opened the Recordsetclone in a different eventprocedure!
ReplyDeletePrivate Sub cmd1_Click()
Dim str As String
Dim I As Integer
I = w1dia
If rs.State = 1 Then
rs.Close
str = "Select * from AXLEMASTERS where W1Dia = " & w1dia & ";"
rs.Find "W1Dia = " & Txt1.Text
If not rs.NoMatch Then ' the record found
'do what you want to do here when the record is found
cr1.ReportFileName = App.Path & "\lowdia.rpt"
cr1.DataFiles(0) = App.Path & "\LocoShed.mdb"
cr1.Action = 1
Else
MsgBox "Record not found"
End If
End If
rs.close
End Sub
If it gives error again note down the Error Message with Error Number and given feed back.
lol a couple of the reviews bloggers write are just silly and unrelated, sometimes i wonder whether they at all read the post before writing or whether they merely look at the subject of the post and write the very first thought that comes to their minds. But it is nice to find a fresh commentary every now and then in contrast to the exact same, traditional blog garbage which I oftentimes notice on the blogs. Cheers
ReplyDeletehi dear friend
ReplyDeleteafter administrator is working
i want to show the users a custom text like
"admin is working please try later "
Could i do ???
thanks before
farzad From Iran
hi dear friend
ReplyDeletein first what was this pop up in your site openning ???!!!
Question : how can i get autonumber in a query ?
i Tryed with Count function but is not working well
if query have some result such as below mention
ID TagNo Description
1 A .......
4 B .......
9 C .......
i want had
Autonumber ID TagNo Description
1 1 A .......
2 4 B .......
3 9 C .......
Every time i Run this Query by other Result i want had Autonumber for new Result
Thanks Before
HI
ReplyDeleteI have one more Question please pay Attention to me
what permission i must to active for user that could Run a "Make Table Query"
for mention you know that before Run this Queries we have no any table for permission and every time we Run a make table Queries this table will delete and recreated
Thanks for your time
Open the Make-Table Query in Design View
ReplyDeleteDisplay the Query Property Sheet
Change the Run Permissions Property Value from User's to Owner's
Save the Query with the change.
Open and read the following Article and follow the instructions carefully:
ReplyDeletehttp://www.msaccesstips.com/2010/01/auto-numbering-in-query-column/
The Popup above the default theme menu is a new Menu Bar. You can select any Article directly from this pop-up Menu.
ReplyDeleteRegards,
Thanks, found the article on google...
ReplyDeleteNice Post mate...
hi dear,
ReplyDeletei have downloaded your demo but when i run the demo i always getting error Undefined function 'Environ' in expression. i have attached Microsoft Visual Basic for Application Extensibility 5.3 as you suggested in the old post.
please help to solve this problem
Regards,
Hi,
ReplyDeleteThere were some errors in the code. I have corrected them now. Please download the Demo Database again and try it out.
Sorry for the inconveniece.
Regards,
a.p.r.pillai
Hi Admin,
ReplyDeleteI was able to replicate this code into my own by defining a new field for BackUp Path. The code below use to work on our network drive but our network team recently made changes to the network drive (not sure what they did) but this is affecting the daily back up I have replicated. Is there any alternative for this? Please see code below:
[QUOTE]
Public Function SysBackup()
Dim dbPathName, j As Long, t As Date
Dim bckupPath
Dim bkupdate, strBatchFlle As String, qot As String
On Error GoTo sysBackup_Err
qot = Chr$(34)
bkupdate = Nz(DLookup("bkupdate", "Bkup_ctrl"), 0)
If bkupdate = Date Or bkupdate = 0 Then
Exit Function
End If
MsgBox "Daily Backup Procedure initiated, please wait...OK."
bckupPath = DLookup("BkupFolderPath", "Bkup_ctrl")
dbPathName = DLookup("dbLink", "Bkup_ctrl")
j = InStrRev(dbPathName, "\")
If j > 0 Then
strBatchFlle = Left(dbPathName, j)
strBatchFile = strBatchFlle & "bakup.bat"
Open strBatchFile For Output As #1
Print #1, "@Echo off"
Print #1, "Echo :------------------------- "
Print #1, "Echo : " & dbPathName
Print #1, "Echo Daily Backup to "; bckupPath; ""
Print #1, "Echo :------------------------- "
Print #1, "Echo : "
Print #1, "Echo :Please wait... "
Print #1, "Echo : "
Print #1, "Copy " & qot & dbPathName & qot & " " & qot & bckupPath & qot
'add lines here for Back-end database or for other Files
Close #1
'Copy file
Call Shell(strBatchFile, vbNormalFocus)
t = Timer
Do While Timer <= t + 10
DoEvents 'wait for 10 seconds
Loop
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE Bkup_Ctrl SET Bkup_Ctrl.bkupdate = Date(), Bkup_Ctrl.workstation = Environ('USERNAME'), Bkup_Ctrl.UserStamp = CurrentUser(), Bkup_Ctrl.TimeStamp = Now() ;"
DoCmd.SetWarnings True
MsgBox "Daily Backup Done Successfully."
'Kill strBatchFile
End If
sysBackup_Exit:
Exit Function
sysBackup_Err:
MsgBox Err.Description, , "sysBackup()"
Resume sysBackup_Exit
End Function
[\QUOTE]
Probably your Network Drive mapping got changed. If you are backing up your database from your local drive to the Network Drive then you may face problems. You can check the current Network Drive mapping through Windows Explorer. The Drive mapping will show something like the example given below, along with other local Drives:
ReplyDeletemyFolder (\\ServerName) (T:)
Earlier, if your Drive letter changed for the same network path \\Servername\myFolder then you can ask the Network Administrator to map the Server Location \\Servername\myFolder to your old Drive Letter.
If you are backing up the Database from Server to local drive then create the Batch File on Server Drive, where your database is, and specify only Database Name alone in the Source Path part in the Copy command. When the batch file is run it will take the database name from the batch file path by default.
Sorry Admin, my real problem is this. With the above code and changes made to our network drive, it is no longer working when the database was located in the network drive but if it is on the local drive, it is running. The error I am getting is :
ReplyDelete"Invalid procedure call or argument"
The code above works if the database was in local drive but not in network drive. Any alternatives you can suggest?
Always save the Batch File on local drive. When Database is on Network Drive take backup on Local Drive. Specify the Source and Target Path in the Copy DOS Command line correctly.
ReplyDeleteWhen the Database or the Backup file is on Network Drive it will be included in the Daily Network backup by the Network Administrators. If something happens to your database you can always request them to restore the database from the latest Network backup Tape.
If you can post the modified version of the code here, I can check whether every thing with the code is ok or not.
Check whether you have Windows Network or some other Network Software. Network Administrators can give you this information.
Hi Admin,
ReplyDeleteOur network admininstrators does not have a daily back up but I think it is weekly. I need an alternate code that will work on our network drive as the below code works on our local drive.
PLease see below code. I have a table named Bkup_ctrl where I look up the link to database and the back up path. I am using a splitted database Front end and back end.
Public Function SysBackup()
Dim dbPathName, j As Long, t As Date
Dim bckupPath
Dim bkupdate, strBatchFlle As String, qot As String
On Error GoTo sysBackup_Err
qot = Chr$(34)
bkupdate = Nz(DLookup("bkupdate", "Bkup_ctrl"), 0)
If bkupdate = DATE Or bkupdate = 0 Then
Exit Function
End If
MsgBox "Daily Backup Procedure initiated, please wait...OK."
bckupPath = DLookup("BkupFolderPath", "Bkup_ctrl")
dbPathName = DLookup("dbLink", "Bkup_ctrl")
j = InStrRev(dbPathName, "\")
If j > 0 Then
strBatchFlle = Left(dbPathName, j)
strBatchFile = strBatchFlle & "bakup.bat"
Open strBatchFile For Output As #1
Print #1, "@Echo off"
Print #1, "Echo :------------------------- "
Print #1, "Echo : " & dbPathName
Print #1, "Echo Daily Backup to "; bckupPath; ""
Print #1, "Echo :------------------------- "
Print #1, "Echo : "
Print #1, "Echo :Please wait... "
Print #1, "Echo : "
Print #1, "Copy " & qot & dbPathName & qot & " " & qot & bckupPath & qot
'add lines here for Back-end database or for other Files
Close #1
'Copy file
Call Shell(strBatchFile, vbNormalFocus)
t = Timer
Do While Timer <= t + 20
DoEvents 'wait for 10 seconds
Loop
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE Bkup_Ctrl SET Bkup_Ctrl.bkupdate = Date(), Bkup_Ctrl.workstation = Environ('USERNAME'), Bkup_Ctrl.UserStamp = CurrentUser(), Bkup_Ctrl.TimeStamp = Now() ;"
DoCmd.SetWarnings True
MsgBox "Daily Backup Done Successfully."
'Kill strBatchFile
End If
sysBackup_Exit:
Exit Function
sysBackup_Err:
MsgBox Err.Description, , "sysBackup()"
Resume sysBackup_Exit
End Function
Please provide the following details:
ReplyDeleteYour Network Drive mapping Address, where the backup copy is targetted. It will look like: SharedDocs (\\ServerName\FolderName) (T:). Use Windows Explorer to find out.
Local Drive Path where the Back-end and Front-end databases are located.
The following field values from the Backup_Ctrl Table:
BkupFolderPath = ?
dblink = ?
Hi,
ReplyDeleteI downloaded the demo that works wonderful. When I copy and paste all the codes in the module, and also on load and on timer, there is no action. My access file is accdb, Access 2007. I'm really confused.
Hi,
ReplyDeletewhat is "object required" error? When I run your demo code, it comes up.
Hi,
ReplyDeleteDisable the following line from running by putting single quote in the first column as shown below:
'On Error GoTo sysBackup_Err
When the error message pops up select the Debug option to stop the Code on the error line and note it down. Please let me know where exactly the code runs into error. Perhaps you may need to attach the DAO reference library file.
Check whether the On Load and On Timer Event properties are loaded with the [Event Procedure] values. If not select it from the drop-down control on the property.
ReplyDeleteHi, I have found your tutorial very interesting by the way I want it to backup automatically on a schedule time like every 7h PM and to check that the .mdb file isn't open before doing it. Any help like the code or the file itself would be greatly appreciate.
ReplyDeleteThanks
I think, the best and easy approach is to use Windows Backup/Restore Utility (Start-->Control Panel-->Backup and Restore). You can schedule Automatic Backups, save file(s) on external storage devices, on a specific time on Daily/Weekly/Monthly frequency. You can select specific Files/Folders/Drive to backup as well.
ReplyDeleteSince, you have gone through the Daily backup method explained on this page, check the automatic email alerts scheduling trick on this post:Automated EMail Alers for setting up time schedule and checking. You must setup programs that runs at specific intervals (say at every minute) and compare the target time with the computer's clock to determine whether the time has reached to transfer control to the Backup Program.
Open status of the database can be checked for the presence of a lock file with the same name of the database but with the file extension .ldb (access2003) or .laccdb (access2007). Check this link: Who is Online to learn some trick with this file.