August 2006

A better way with a Make Table Query?

The situation.  

Back end Access DB, front ended with an Excel Form. Add a new record to a table in the DB and run a Make Table Query to sort the whole table in to alphabetical order. Reload the table into a list box.

I need to make a new table because simply sorting the existing table does not results in a alphabetica import into the list box.

The problem is that when I run the SQL for the update query, if the table name is the same as a table already in the DB then DAO errors. In Access you have to click a message box to allow the deletion of the old table.

From VBA I can use DAO with  “TableDefs.Delete” to remove the old table then the solution works fine.  But I don’t really like this idea, it is clunky and I don’t like deleting table danger!

So what’s a better way?
The workhorse code looks like this:

[vba]Sub SendNewProject(sPro As String, sDes As String)

    Dim i As Integer
    Dim db As Database, rs As Recordset, r As Long
    Dim sSql As String

    Set db = OpenDatabase(gsDataBase)
    Set rs = db.OpenRecordset(“tblProject”, dbOpenTable)

    With rs
        .AddNew
        .Fields(“Project”) = sPro
        .Fields(“Description”) = sDes
        .Update
    End With

    ”’close table we will delete shortly
    rs.Close
    Set rs = Nothing

    ”’run updatequery to update project list
    sSql = ” SELECT tblProject.Project INTO tblProjectS” _
           & ” FROM tblProject” _
           & ” ORDER BY tblProject.Project;”

    ”’delete old projectsS table
    db.TableDefs.Delete “tblProjectS”
    ”’run make new table
    db.Execute sSql

    ”’close DB
    db.Close
    Set db = Nothing

    MsgBox “Project has been added to the projects list” _
           & vbNewLine _
           & vbNewLine _
           , vbOKOnly, gcsMsgboxhead

End Sub [/vba]

Securing VBA code in Office

Most of us know that .dll’s are the only real option if security is a genuine issue, but I think the following might be a possible (bodge) solutions for those who many not have VB, and need better security for their VBA code. Anyway, I was looking at this site:

Tech Net – Office 2000/Visual Basic Programmer’s Guide

Chapter 17 deals with security. My lighting fast brain crawled in to action and I thought I’d try something.

Now according to this info:

In Access, you can save an .mdb or .adp file as a file type that contains only compiled VBA code without the source code.

These files are called .mde file and most of us will have worked with these before, or at least heard of them. I didn’t know the code was compiled though. Doing a little bit of goggling it seems that decompiling is available, but that the VBA code remains compiled, i.e. forms and report are easy to decompile, but the VBA remains compiled good news.

See where we are heading? You can call this .mde code from you Excel/Word etc VBA, and your more sensitive VBA code can be kept in a complied- harder to get at – .mde file. In theory it’s a bit like putting your code in a proper .dll it’s compiled code. Which kinda begs the question, why can you do this with all our VBA?

Here is an example I’ve put it into a UDF, and it runs in such a way as to be dog slow, but it could be implemented better, or if the situations was different the performance hit would be less noticeable I’m sure you’ll get the idea. I’ve inculed the orginal mdb, and you can do all the other passwording etc to this mde before making it a mde. I’ve also chnaged the file extention to change the icon, whcih is of little importance.

So, it’s Heath Robison, it’s far from ideal but it might be useful to someone; oneday! A nice little idea I though”¦Â 

The trouble with data”¦

Here’s a new blog that should be good! It’s from Uk base developer Will Riley, and Xl Dennis is helping out too. You might even find out some floor tips, so there you go!

willsblog.JPG

http://www.wills-blog.com/

oh, and good luck Will!

Some links and content form real bloggers!

A few intresting items have appread in my bloglines tonight:

Firstly some Office Developer vedios are up on MSDN:

http://msdn.microsoft.com/office/ 

Second, tell me if you’ve ever been developing in this office:

dwb.jpg

I don’t think she’s gunna get much done…..

and lastly some VBA/VSTA info…now I’ve not even read this yet my self, but I’m going to just to find out what VSTA actaull is and how it differs from VSTO. I rember Mark (Wielgus)  talking about this ages ago!

http://blogs.msdn.com/pstubbs/archive/2006/07/31/684576.aspx 

p.s, it’s midnight and I’m still working (just!), that’s why I post once a month I guess!!!