MS Access - Archive Tables then Import new Tables via VBScript if possible

Posted on 2009-02-16
Medium Priority
Last Modified: 2012-08-13

I have a very large question that I was wondering if anybody here could help.

We use "Retina" as our network security scanner at work.  It's a fairly decent program that audits any and all vulnerabilities on workstations accross the whole enterprise.  When you run a scan using Retina, it saves the information as a file with an "rtb" extension that can be opened in MS Access to view all the tables, etc.

My question is then, I have an MS Access database that's tracking the mitigation of all the vulnerabilites in our network, up to the point of resolve.  There's a TON of cutting/pasting involved, but what I'd like to do - is create a button on a form, or use a function in access - that does alot of that work for me.

I'd like to have a button that I push that asks where the Retina filename is stored.  It would then backup all the previous data into an archive of sorts, then purge the tables of anything - and then import the new data from the RTB file into the required tables.

The RTB file structure is always the same as far as the tables, etc. are concerned - the only difference between scans is the filename of whatever we give it for that particular day.

Any information you guys can provide would be greatly appreciated on this topic.  Thanks in advance.
Question by:usslindstrom
  • 5
  • 2
LVL 11

Expert Comment

ID: 23657154
SQL Server for Storage

So far as achiving goes, i'd suggest you look at implementing a sql server of some description to hold all of your data within the one database.  I would recreate the structure of the tables that you need to archive, but put an addition int field in each and map this to a fact table containing the name/path to the source access database.

If the rtb files are always in the same folder, then i would just write a visual basic script or exe file to find the files that have not yet been imported and then suck the data in.

Using this method the whole process could be scheduled.


Author Comment

ID: 23657608
That VBscript or EXE solution would be great.

Unfortunately - at current I don't have access to a SQL server that I could inject any of the tables into, and M.S. A is my only hope (sounds like Star Wars when I say it that way).

I'd be content with just having the database archived within Access, as it's never really that much data to begin with (maybe 50 record sets each import) - or maybe even creating a separate mdb that just holds archival info.  **A solution here, could be to just export the relevent tables into a database by themselves and named by the date/time they were backed up...   Really, any solution would be more than exceptable (but the powers that be wouldn't let me stand up a SQL server *even mySQL or SQLExpress* just to store this data)

I'm not as up to speed on VB as I'd like to be, but if possible, could you point me in the right direction to implement the scripting to be able to pull off the import / export function that you mentioned in your post?

Thanks for any help you can provide.
LVL 11

Assisted Solution

mildurait earned 2000 total points
ID: 23679124
Sorry for the delay, but here's a starting point.

Destination table(s)
a) In your destination database, create the table(s) with the same fieldnames, datatypes etc with the exception of the autonumber field, make it of type long.
b) Add an autonumber field maybe called iRecordID, set it to primary key
c) and a field of long type called iFileID.

File Table
Create a table called tblFile in the destination database with fields (iFileID - Autonumber, sFileConnectionString string)

Code snippet below
This will need some massaging and extending (to loop through all files in a directory using DIR) but will give you the general idea. You will need to save the file as [yourfilename].vbs

Visit http://www.connnectionstrings.com for assistance in constructing connection strings.

Private Sub CopyTable(ByVal SourceCS,ByVal DestCS,ByVal TableName)
      'Get file id or write connection string to database tblFile
      Dim FileID
      set rsFile = Server.CreateObject("adodb.recordset")
      rsFile.Open("SELECT iFIleID,sFileConnectionString FROM tblFile WHERE sFileConnectionString=" & chr(34) & SourceCS  & Chr(34))
      with rsFile
            if .eof then
                  FileID = 0
                  .fields("sFileConnectionString").value = SourceCS
                 FileID = .fields("iFileID").value
            End If
       end with
      If FileID=0 then
          rsFile.Open("SELECT iFIleID,sFileConnectionString FROM tblFile WHERE sFileConnectionString=" & chr(34) & SourceCS  & Chr(34))
          FileID = rsFile.fields("iFileID").value
      End If 
      set rsFile = nothing
      'Open source and destination objects, and copy data
      set rsSource = Server.CreateObject("adodb.recordset")
      rsSource.Open("SELECT * FROM " & TableName,SourceCS)
      rsDest = Server.CreateObject("adodb.recordset")
      rsDest.Open("SELECT * FROM " & TableName & " WHERE 1=2")
      while rsSource.eof = false
            for each f in rsSource.fields         
                 rsDest.fields(f.name).value = rsSource.fields(f.name).value
           rsDest.fields("FileID").value = FileID
     set rsDest = nothing
     set rsSource = nothing
End Sub
'Run the sub
Call CopyTable("YourSourceConnectionString","YourDestConnectionString","tblData1")
Call CopyTable("YourSourceConnectionString","YourDestConnectionString","tblData2")

Open in new window

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

LVL 11

Accepted Solution

mildurait earned 2000 total points
ID: 23679132
line 28 should be rsDest.Open("SELECT * FROM " & TableName & " WHERE 1=2", DestCS)
LVL 11

Assisted Solution

mildurait earned 2000 total points
ID: 23679145
lines 6, 19 should be
rsFile.Open("SELECT iFIleID,sFileConnectionString FROM tblFile WHERE sFileConnectionString=" & chr(34) & SourceCS  & Chr(34),DestCS)

Open in new window


Author Closing Comment

ID: 31547605
So sorry for the late response here.  Sometimes (rather - ALWAYS) - work requirements change from day to day and I sometimes find myself having a hard time coming back and following through on a previous project.

I was able to successfully implement your code and after a little massaging, get it to do exactly what I needed.  Thank you very much for the solution here, I greatly appreciate it.
LVL 11

Expert Comment

ID: 23975571
No problems. Glad to hear you've achieved a good outcome.

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question