Save and Wipe

tango

New Member
Joined
Jun 24, 2004
Messages
5
We are using a database that at the end of the fiscal year gets copied then is saved as an archived (never really looked at again). Then all the information in the original is wiped the auto number is reset and we start all over again. Since we have new people coming and going it would be advisable to make the whole things as simple as possible. So saying that I was wondering is anyone happens to know where there would be an example of macros that would do that or a couple of them I could combine. Or have any other suggestions to do that would be great as well.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
One way would be to use some thing like:-
Code:
Sub DelData()
Dim strSQL As String
DoCmd.SetWarnings False

strSQL = "DELETE Table1.* FROM Table1;"
DoCmd.RunSQL strSQL

strSQL = "DELETE Table2.* FROM Table2;"
DoCmd.RunSQL strSQL


DoCmd.SetWarnings True
End Sub

and work your way through all of the tables you want to clear.
Depending on the version of Access that you are using you can set Acces to compact on close, this should reset the Autonumbers for you, but some versions of Access wont reset Autonumbers on compact.

I would recomend adding a warning box to the code to stop someone running it accidently and wiping out all of your data though!!

Peter
 
Upvote 0
That works great, The compacting works but I don’t know how to do that on close of that one time only. The only other thing that I need to do is make a save location. If there is some way to record macro’s that I am unaware of then it would be pretty simple. I wouldn’t be surprised since I know Access no where near as good as excel and I only sort of know excel.
 
Upvote 0
I don't know of a way to make Access save itself with a new name but you could create and run a batch file to copy it.
The following code will copy it with a new name based on the date.
This works OK on my Machine with W2K and AccessXP
Code:
Sub copyDb()
Dim str As String
Dim strCopyPath As String
Dim strSavePath As String
' path to save file to
strSavePath = "O:\Helpers\xxx\"
str = Format(Date, "YYYYMMDD")
str = "copy " & Application.CurrentProject.FullName & " " & strSavePath & str & ".mdb"
Open strSavePath & "CopyFile.bat" For Output As #1    ' Open file for output.
Print #1, str
Close #1    ' Close file.
Shell (strSavePath & "CopyFile.bat") ' run created .bat file
End Sub

HTH

Peter
 
Upvote 0
Thanks that worked. I was wondering if you or anyone else knows a site that has macro examples that might help a newbi learn how they work and what does what.
 
Upvote 0

Forum statistics

Threads
1,221,713
Messages
6,161,463
Members
451,708
Latest member
PedroMoss2268

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