Documente Academic
Documente Profesional
Documente Cultură
45.8K
521
34
3.76 (8 votes)
Rate: vote 1vote 2vote 3vote 4vote 5
This is an Add-in for Microsoft Access that allows writing and execution of SQL statements
with transaction control
Is your email address OK? You are signed up for our newsletters but your email
address is either unconfirmed, or has not been reconfirmed in a long time. Please click here to
have a confirmation email sent so we can confirm your email address and start sending you
newsletters again. Alternatively, you can update your subscriptions.
Download source files - 46.1 KB
ImmSQL.zip
Introduction
This project is an Access 2003 add-in written in VBA. It allows users to write and to execute
subsequent DML SQL statements with transaction control. This tool is useful when you want
to modify data using SQL queries that affect multiple records in multiple tables.
At the end, after a careful check, you can commit the entire transaction. Modifications in
Microsoft Access records are committed by moving across fields or rows and, very often,
rollback is impossible. This add-in avoids this behavior. The users can also have a preview of
the affected changes over multiple tables before committing the work.
Background
Often, modification queries do not produce intended results. In this case, if the user doesn't
have a backup copy of the database, you could have serious problems trying to recreate the
initial state. I have crreated an MDA Access add-in which permits the writing of SQL
statements (SELECT, INSERT, UPDATE, DELETE) and their execution within a transaction, which
can be committed or discarded.
Points of interest
The view management is very simple. It is interesting code that executes statements:
Hide Shrink
Copy Code
The connection is set when the window is loaded. Then the statement is executed with an
ADODB.Command. The Transaction is managed through ADODB.Connection. If the statement
returns a recordset, then the results are displayed by calling the OpenTempTable subroutine.
The statement executed is registered into an internal table "_Statements" by calling the
InsertIntoStatements subroutine.
The OpenTempTable subroutine is interesting because it uses some internal Access functions
to create a temp form. The sub adds as many textboxes as fields in the recordset and then
binds them to the transacted recordset. At the end, the records are shown as a datasheet to
seem like a true Access table:
Hide Shrink
Copy Code
frmname = "_tmpForm"
'Make a copy of form2 which is used as a template
On Error Resume Next
DoCmd.Close acForm, frmname
DoCmd.DeleteObject acForm, frmname
On Error GoTo 0
DoCmd.CopyObject , "_tmpForm", acForm, "Form2"
'Open the _tmpForm in design mode to allow editing
DoCmd.OpenForm frmname, acDesign, , , , acHidden
'Add a bound text box for each fields
For Each f In r.Fields
With CreateControl(frmname, acTextBox)
' set control properties
.Name = f.Name
.Properties("ControlSource") = f.Name
End With
Next
DoCmd.OpenForm frmname, acFormDS
Set Forms(frmname).Recordset = r
Forms(frmname).Refresh
DoCmd.Save acForm, frmname
End Sub
InsertIntoStatements subroutine shows how to access add-in hidden tables through
CodeProject.AccessConnection rather than CurrentProject.Connection or
CurrentProject.AccessConnection. Firstly, the subroutine checks if the statement is
different from the last statement executed. If it is different, you have to insert the statement in
an internal table. Then, if there are more than 15 statements, you have to delete the older one:
Hide Shrink
Copy Code
I think this tool could be evolved in order to create and automate Database scripts to upgrade,
clean or move data.
History
License
This article has no explicit license attached to it but may contain usage terms in the article text
or the download files themselves. If in doubt please contact the author via the discussion
board below.
A list of licenses authors might use can be found here
Share
email
twitter
FrankNight
CEO Gekoproject.com
Italy
No Biography provided