We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


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

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.
Watch Question


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.


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.
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
line 28 should be rsDest.Open("SELECT * FROM " & TableName & " WHERE 1=2", DestCS)
lines 6, 19 should be
rsFile.Open("SELECT iFIleID,sFileConnectionString FROM tblFile WHERE sFileConnectionString=" & chr(34) & SourceCS  & Chr(34),DestCS)

Open in new window


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.

No problems. Glad to hear you've achieved a good outcome.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.