I just use this concept called 'chapters' where I name all of my
action queries like this:
QA01_NewGroup_101
QA02_GroupLetter_201
QA02_GroupLetter_202
It isn't the prettiest code; I'm going to rewrite it as a CLR sproc
sometime soon; I just haven't gotten around to it
Option Compare Database
Option Explicit
Public cnn As ADODB.Connection
Public Enum chapPhase
chapDDL = 0 'L - DDL query
chapFlash = 1 'F - flash query
chapDelete = 3 'D - delete query
chapAppend = 4 'A - append query
chapUpdate = 5 'U - update query
chapSelect = 6 'S - doesn't really 'do' anythign; this is a way to
keep queries on top of queries organized
chapError = 7 'E - execute a query; if rst.fields(0).value = True
then stop processing
End Enum
Public Function FlashAllActiveQueries()
On Error GoTo errHandler
Set cnn = New ADODB.Connection
cnn.ConnectionString = CurrentProject.Connection.ConnectionString
cnn.Open
Dim D_START As Date
Dim D_END As Date
Dim I_LEN As Integer
Dim S_Msg As String
Dim I As Byte
D_START = Now()
For I = 1 To 99
Call ProcessChapter(I)
Next I
D_END = Now()
I_LEN = DateDiff("S", D_START, D_END)
S_Msg = "Processing completed " & vbCrLf & " Number of seconds: " &
I_LEN
Debug.Print Now() & " : " & S_Msg
cleanExit:
Exit Function
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
End Function
Public Sub ProcessChapter(chapterMask As Byte)
On Error GoTo errHandler
If chapterMask < 0 Or chapterMask > 99 Then
MsgBox "ChapterMask must be 2 characters; and it can only contain
characters 0-9 and A-F."
End
End If
Dim S_ChapterWithX As String
S_ChapterWithX = "'QX" & Right("0" & chapterMask, 2) & "'"
MsgBox S_ChapterWithX, vbOKOnly
Dim S_DDLLike As String
Dim S_FlashLike As String
Dim S_ImportLike As String
Dim S_DeleteLike As String
Dim S_UpdateLike As String
Dim S_AppendLike As String
S_DDLLike = "'QL" & Right(S_ChapterWithX, Len(S_ChapterWithX) - 3)
S_ImportLike = "'QI" & Right(S_ChapterWithX, Len(S_ChapterWithX) - 3)
S_FlashLike = "'QF" & Right(S_ChapterWithX, Len(S_ChapterWithX) - 3)
S_DeleteLike = "'QD" & Right(S_ChapterWithX, Len(S_ChapterWithX) - 3)
S_UpdateLike = "'QU" & Right(S_ChapterWithX, Len(S_ChapterWithX) - 3)
S_AppendLike = "'QA" & Right(S_ChapterWithX, Len(S_ChapterWithX) - 3)
'go through and run all of the 'Flash queries' for a particular
chapter..
'then
'go through and run all of the 'Update queries' for a particular
chapter..
Dim rst As New ADODB.Recordset
rst.Open "Select [name] from sysobjects where xtype = 'P' AND
LEFT([name], 4) = " & S_DDLLike & " ORDER BY [NAME]", cnn
Do Until rst.EOF
FlashDDLThisQuery (rst!Name)
rst.MoveNext
Loop
Set rst = Nothing
Set rst = New ADODB.Recordset
rst.Open "Select [name] from sysobjects where xtype = 'P' AND
LEFT([name], 4) = " & S_ImportLike & " ORDER BY [NAME]", cnn
Do Until rst.EOF
FlashImportThisQuery (rst!Name)
rst.MoveNext
Loop
Set rst = Nothing
Set rst = New ADODB.Recordset
rst.Open "Select [name] from sysobjects where xtype = 'V' AND
LEFT([name], 4) = " & S_FlashLike & " ORDER BY [NAME]", cnn
Do Until rst.EOF
FlashThisQuery (rst!Name)
rst.MoveNext
Loop
Set rst = Nothing
Set rst = New ADODB.Recordset
rst.Open "Select [name] from sysobjects where xtype = 'P' AND
LEFT([name], 4) = " & S_DeleteLike & " ORDER BY [NAME]", cnn
Do Until rst.EOF
FlashDeleteThisQuery (rst!Name)
rst.MoveNext
Loop
Set rst = Nothing
Set rst = New ADODB.Recordset
rst.Open "Select [name] from sysobjects where xtype = 'P' AND
LEFT([name], 4) = " & S_UpdateLike & " ORDER BY [NAME]", cnn
'MsgBox S_UpdateLike, vbOKOnly
Do Until rst.EOF
FlashUpdateThisQuery (rst!Name)
rst.MoveNext
Loop
Set rst = Nothing
Set rst = New ADODB.Recordset
rst.Open "Select [name] from sysobjects where xtype = 'P' AND
LEFT([name], 4) = " & S_AppendLike & " ORDER BY [NAME]", cnn
'MsgBox S_AppendLike, vbOKOnly
Do Until rst.EOF
FlashAppendThisQuery (rst!Name)
rst.MoveNext
Loop
Set rst = Nothing
cleanExit:
DoCmd.SetWarnings True
Exit Sub
failexit:
GoTo cleanExit
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
End Sub
Public Sub FlashThisQuery(strQry As String)
On Error GoTo errHandler
Dim strTbl As String
Dim S_result As String
Dim B_tblExists As Boolean
strTbl = "T" & Right(strQry, Len(strQry) - 1)
'Dim S_TABLEDELETE As String
'S_TABLEDELETE = "if exists (select 1 from sysobjects where name = '"
strTbl & "') " & vbCrLf & _
' "BEGIN " & vbCrLf & _
' "DROP TABLE " & strTbl & vbCrLf & _
' " END"
'
'
'DoCmd.RunSql S_TABLEDELETE, False
Dim strSql As String
strSql = " IF EXISTS(Select 0 from sysobjects where id =
OBJECT_ID('dbo." & strTbl & "')) "
strSql = vbCrLf & strSql & " BEGIN "
strSql = vbCrLf & strSql & " DROP TABLE dbo.[" & strTbl & "] "
strSql = vbCrLf & strSql & " End "
strSql = vbCrLf & strSql & " Select *, GETDATE() AS DateFlashed INTO
dbo.[" & strTbl & "] FROM [" & strQry & "]"
'DoCmd.RunSQL "EXEC " & strQry
DoCmd.RunSQL strSql
cleanExit:
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
Resume
End Sub
Public Sub FlashDDLThisQuery(strQry As String)
On Error GoTo errHandler
If Left(strQry, 2) <> "qL" Then
MsgBox "DDLFlash Name should look like 'QL'"
End
End If
'DoCmd.RunSQL "EXEC " & strQry
DoCmd.RunSQL strQry
cleanExit:
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
Resume
End Sub
Public Sub FlashInsertThisQuery(strQry As String)
On Error GoTo errHandler
If Left(strQry, 2) <> "QI" Then
MsgBox "InsertFlash Name should look like 'QI'"
End
End If
'DoCmd.RunSQL "EXEC " & strQry
DoCmd.RunSQL strQry
cleanExit:
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
Resume
End Sub
Public Sub FlashDeleteThisQuery(strQry As String)
On Error GoTo errHandler
If Left(strQry, 2) <> "qd" Then
MsgBox "Delete QueryFlash Name should look like 'QD'"
End
End If
'DoCmd.RunSQL "EXEC " & strQry
DoCmd.RunSQL strQry
cleanExit:
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
Resume
End Sub
Public Sub FlashUpdateThisQuery(strQry As String)
On Error GoTo errHandler
If Left(strQry, 2) <> "qu" Then
MsgBox "Standard Update Query should be named like 'QU'"
End
End If
'DoCmd.RunSQL "EXEC " & strQry
DoCmd.RunSQL strQry
cleanExit:
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
End Sub
Public Sub FlashImportThisQuery(strQry As String)
On Error GoTo errHandler
If Left(strQry, 2) <> "QI" Then
MsgBox "Standard Import Query should be named like 'QI'"
End
End If
'DoCmd.RunSQL "EXEC " & strQry
DoCmd.RunSQL strQry
cleanExit:
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
End Sub
Public Sub FlashAppendThisQuery(strQry As String)
On Error GoTo errHandler
If Left(strQry, 2) <> "qa" Then
MsgBox "Standard Append Query should be named like 'qa'"
End
End If
'DoCmd.RunSQL "EXEC " & strQry
DoCmd.RunSQL strQry
cleanExit:
Exit Sub
errHandler:
MsgBox "Append Failure: " & strQry & vbCrLf & Err.Number & " - " &
Err.Description, vbOKOnly
Resume Next
End Sub