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

Experts,

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.
LVL 5
usslindstromAsked:
Who is Participating?
 
milduraitConnect With a Mentor Commented:
line 28 should be rsDest.Open("SELECT * FROM " & TableName & " WHERE 1=2", DestCS)
0
 
milduraitCommented:
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.







0
 
usslindstromAuthor Commented:
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.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
milduraitConnect With a Mentor Commented:
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
                  .addnew
                  .fields("sFileConnectionString").value = SourceCS
                  .update
            Else
                 FileID = .fields("iFileID").value
            End If
       end with
      rsFile.close
      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
            rsDest.addnew
            for each f in rsSource.fields         
                 rsDest.fields(f.name).value = rsSource.fields(f.name).value
           next
           rsDest.fields("FileID").value = FileID
           rsDest.update
           rsSource.movenext
      wend
     rsDest.close
     rsSource.close
     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

0
 
milduraitConnect With a Mentor Commented:
lines 6, 19 should be
rsFile.Open("SELECT iFIleID,sFileConnectionString FROM tblFile WHERE sFileConnectionString=" & chr(34) & SourceCS  & Chr(34),DestCS)

Open in new window

0
 
usslindstromAuthor Commented:
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.
0
 
milduraitCommented:
No problems. Glad to hear you've achieved a good outcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.