diff --git a/access-add-in/source/AccUnitLoaderForm.frm b/access-add-in/source/AccUnitLoaderForm.frm new file mode 100644 index 0000000..70941a5 Binary files /dev/null and b/access-add-in/source/AccUnitLoaderForm.frm differ diff --git a/access-add-in/source/AccUnitUserSettings.frm b/access-add-in/source/AccUnitUserSettings.frm new file mode 100644 index 0000000..9419c67 Binary files /dev/null and b/access-add-in/source/AccUnitUserSettings.frm differ diff --git a/access-add-in/source/dbs-properties.json b/access-add-in/source/dbs-properties.json index 0367d48..576124f 100644 --- a/access-add-in/source/dbs-properties.json +++ b/access-add-in/source/dbs-properties.json @@ -105,7 +105,7 @@ "Type": 4 }, "NavPane Width": { - "Value": 545, + "Value": 577, "Type": 4 }, "Never Cache": { diff --git a/access-add-in/source/forms/AccUnitLoaderForm.form b/access-add-in/source/forms/AccUnitLoaderForm.form index 4a7af75..70e597c 100644 --- a/access-add-in/source/forms/AccUnitLoaderForm.form +++ b/access-add-in/source/forms/AccUnitLoaderForm.form @@ -102,13 +102,13 @@ Begin Form GridlineShade =65.0 End Begin Section - Height =5160 + Height =5220 Name ="Detail" Begin Begin CommandButton TabStop = NotDefault OverlapFlags =85 - Left =9900 + Left =9840 Top =120 Width =600 Height =480 @@ -161,7 +161,6 @@ Begin Form GridlineWidthTop =0 GridlineWidthRight =0 GridlineWidthBottom =0 - ColumnStart =6 ColumnEnd =6 LayoutGroup =1 @@ -192,7 +191,6 @@ Begin Form GridlineWidthTop =0 GridlineWidthRight =0 GridlineWidthBottom =0 - ColumnStart =2 ColumnEnd =5 LayoutGroup =1 @@ -232,7 +230,6 @@ Begin Form Width =0 Height =0 Name ="sysFirst" - End Begin CommandButton Transparent = NotDefault @@ -245,14 +242,13 @@ Begin Form Name ="cmdClose" Caption ="Schließen" OnClick ="[Event Procedure]" - End Begin CommandButton TabStop = NotDefault OverlapFlags =85 Left =2760 Top =1380 - Width =4920 + Width =4980 Height =420 TabIndex =5 Name ="cmdSetAccUnitTlbReferenz" @@ -264,7 +260,6 @@ Begin Form GridlineWidthTop =0 GridlineWidthRight =0 GridlineWidthBottom =0 - PictureCaptionArrangement =5 RowStart =2 RowEnd =2 @@ -281,7 +276,7 @@ Begin Form OverlapFlags =85 Left =2760 Top =1980 - Width =4920 + Width =4980 Height =420 TabIndex =6 Name ="cmdRemoveAccUnitTlbReferenz" @@ -294,7 +289,6 @@ Begin Form GridlineWidthTop =0 GridlineWidthRight =0 GridlineWidthBottom =0 - PictureCaptionArrangement =5 RowStart =3 RowEnd =3 @@ -312,7 +306,7 @@ Begin Form OverlapFlags =85 Left =2760 Top =780 - Width =4920 + Width =4980 Height =420 TabIndex =4 Name ="cmdExportAccUnitFiles" @@ -324,7 +318,6 @@ Begin Form GridlineWidthTop =0 GridlineWidthRight =0 GridlineWidthBottom =0 - PictureCaptionArrangement =5 RowStart =1 RowEnd =1 @@ -358,7 +351,7 @@ Begin Form Begin EmptyCell Left =7800 Top =1380 - Width =2700 + Width =2640 Height =420 Name ="EmptyCell78" GroupTable =2 @@ -411,7 +404,6 @@ Begin Form GridlineWidthTop =0 GridlineWidthRight =0 GridlineWidthBottom =0 - PictureCaptionArrangement =5 RowStart =7 RowEnd =7 @@ -423,7 +415,7 @@ Begin Form GroupTable =2 End Begin EmptyCell - Left =9900 + Left =9840 Top =780 Width =600 Height =420 @@ -442,7 +434,7 @@ Begin Form GroupTable =2 End Begin EmptyCell - Left =9900 + Left =9840 Top =1980 Width =600 Height =420 @@ -463,7 +455,7 @@ Begin Form Begin CommandButton TabStop = NotDefault OverlapFlags =85 - Left =9900 + Left =9840 Top =4560 Width =600 Height =480 @@ -478,7 +470,6 @@ Begin Form GridlineWidthTop =0 GridlineWidthRight =0 GridlineWidthBottom =0 - PictureCaptionArrangement =5 RowStart =7 RowEnd =7 @@ -493,7 +484,7 @@ Begin Form Begin CommandButton TabStop = NotDefault OverlapFlags =85 - Left =9900 + Left =9840 Top =3780 Width =600 Height =600 @@ -547,7 +538,6 @@ Begin Form 0x7272720f00000000727272067272728400000000000000007272728472727206 , 0x0000000000000000 End - RowStart =6 RowEnd =6 ColumnStart =6 @@ -595,7 +585,7 @@ Begin Form GroupTable =2 End Begin EmptyCell - Left =5280 + Left =5340 Top =4560 Width =2400 Height =480 @@ -664,7 +654,7 @@ Begin Form OverlapFlags =85 Left =2760 Top =2580 - Width =4920 + Width =4980 Height =420 TabIndex =7 Name ="cmdInstallVbeAddIn" @@ -677,7 +667,6 @@ Begin Form GridlineWidthTop =0 GridlineWidthRight =0 GridlineWidthBottom =0 - PictureCaptionArrangement =5 RowStart =4 RowEnd =4 @@ -710,7 +699,7 @@ Begin Form GroupTable =2 End Begin EmptyCell - Left =9900 + Left =9840 Top =2580 Width =600 Height =420 @@ -754,7 +743,7 @@ Begin Form OverlapFlags =85 Left =2760 Top =3180 - Width =4920 + Width =4980 Height =420 TabIndex =8 Name ="cmdLoadVbeAddIn" @@ -767,7 +756,6 @@ Begin Form GridlineWidthTop =0 GridlineWidthRight =0 GridlineWidthBottom =0 - PictureCaptionArrangement =5 RowStart =5 RowEnd =5 @@ -801,7 +789,7 @@ Begin Form GroupTable =2 End Begin EmptyCell - Left =9900 + Left =9840 Top =3180 Width =600 Height =420 diff --git a/access-add-in/source/forms/AccUnitUserSettings.form b/access-add-in/source/forms/AccUnitUserSettings.form index b9e9979..eb10df0 100644 --- a/access-add-in/source/forms/AccUnitUserSettings.form +++ b/access-add-in/source/forms/AccUnitUserSettings.form @@ -116,7 +116,6 @@ Begin Form Width =0 Height =0 Name ="sysFirst" - End Begin TextBox OverlapFlags =85 @@ -132,7 +131,6 @@ Begin Form BottomPadding =150 HorizontalAnchor =2 ShowDatePicker =0 - ColumnStart =1 ColumnEnd =1 LayoutGroup =1 @@ -173,7 +171,6 @@ Begin Form BottomPadding =150 HorizontalAnchor =2 ShowDatePicker =0 - RowStart =1 RowEnd =1 ColumnStart =1 @@ -223,7 +220,6 @@ Begin Form GroupTable =2 BottomPadding =150 HorizontalAnchor =2 - RowStart =2 RowEnd =2 ColumnStart =1 @@ -268,7 +264,6 @@ Begin Form BottomPadding =150 HorizontalAnchor =2 ShowDatePicker =0 - RowStart =3 RowEnd =3 ColumnStart =1 @@ -317,7 +312,6 @@ Begin Form HorizontalAnchor =2 VerticalAnchor =2 ShowDatePicker =0 - RowStart =4 RowEnd =4 ColumnStart =1 @@ -359,7 +353,6 @@ Begin Form Caption ="Save" OnClick ="[Event Procedure]" VerticalAnchor =1 - End Begin CommandButton Cancel = NotDefault @@ -372,7 +365,6 @@ Begin Form Caption ="Cancel" OnClick ="[Event Procedure]" VerticalAnchor =1 - End End End diff --git a/access-add-in/source/forms/InstallAddInForm.form b/access-add-in/source/forms/InstallAddInForm.form index 77cb85d..28849a2 100644 --- a/access-add-in/source/forms/InstallAddInForm.form +++ b/access-add-in/source/forms/InstallAddInForm.form @@ -17,7 +17,7 @@ Begin Form PictureAlignment =2 DatasheetGridlinesBehavior =3 GridY =10 - Width =7380 + Width =7440 DatasheetFontHeight =11 ItemSuffix =335 Left =1000 @@ -140,7 +140,7 @@ Begin Form GridlineShade =65.0 End Begin Section - Height =7260 + Height =7380 Name ="Detailbereich" AlternateBackThemeColorIndex =1 AlternateBackShade =95.0 diff --git a/access-add-in/source/modVbProject.bas b/access-add-in/source/modVbProject.bas new file mode 100644 index 0000000..c1a3705 --- /dev/null +++ b/access-add-in/source/modVbProject.bas @@ -0,0 +1,92 @@ +Attribute VB_Name = "modVbProject" +'--------------------------------------------------------------------------------------- +' Module: modVbProject +'--------------------------------------------------------------------------------------- +'/** +' +' VBProject ermitteln +' +' +' +' \ingroup base +'**/ +'--------------------------------------------------------------------------------------- +' +' %AppFolder%/source/modVbProject.bas +' _codelib/license.bas +' +'--------------------------------------------------------------------------------------- +' +Option Compare Text +Option Explicit +Option Private Module + +#Const EARLYBINDING = 1 + +Private m_CurrentVbProject As Object + +#If EARLYBINDING Then +Public Property Get CurrentVbProject() As VBIDE.VBProject +#Else +Public Property Get CurrentVbProject() As Object +#End If + +#If EARLYBINDING Then + Dim Proj As VBProject +#Else + Dim Proj As Object +#End If + Dim strCurrentDbName As String + + If m_CurrentVbProject Is Nothing Then + Set m_CurrentVbProject = Application.VBE.ActiveVBProject + If Application.VBE.VBProjects.Count > 1 Then + 'Prüfen, ob das richtige VbProject gewählt wurde (muss das von CurrentDb sein) + strCurrentDbName = UncPath(CurrentDb.Name) + If m_CurrentVbProject.FileName <> strCurrentDbName Then + Set m_CurrentVbProject = Nothing + For Each Proj In VBE.VBProjects + If Proj.FileName = strCurrentDbName Then + Set m_CurrentVbProject = Proj + Exit For + End If + Next + End If + End If + End If + + Set CurrentVbProject = m_CurrentVbProject + +End Property + + +#If EARLYBINDING Then +Public Property Get CodeVBProject() As VBIDE.VBProject +#Else +Public Property Get CodeVBProject() As Object +#End If + +#If EARLYBINDING Then + Dim Proj As VBProject +#Else + Dim Proj As Object +#End If + Dim strCodeDbName As String + Dim objCodeVbProject As Object + + Set objCodeVbProject = VBE.ActiveVBProject + 'Prüfen, ob das richtige VbProject gewählt wurde (muss das von CodeDb sein) + strCodeDbName = FileTools.UncPath(CodeDb.Name) + If objCodeVbProject.FileName <> strCodeDbName Then + Set objCodeVbProject = Nothing + For Each Proj In VBE.VBProjects + If Proj.FileName = strCodeDbName Then + Set objCodeVbProject = Proj + Exit For + End If + Next + End If + + Set CodeVBProject = objCodeVbProject + +End Property diff --git a/access-add-in/source/modules/ApplicationHandler.cls b/access-add-in/source/modules/ApplicationHandler.cls index 6c664cf..532f185 100644 --- a/access-add-in/source/modules/ApplicationHandler.cls +++ b/access-add-in/source/modules/ApplicationHandler.cls @@ -22,8 +22,10 @@ Attribute VB_Description = "Hauptsteuerung der Anwendung" '--------------------------------------------------------------------------------------- ' ' base/ApplicationHandler.cls +' base/modApplication.bas ' _codelib/license.bas ' DAO50{00025E01-0000-0000-C000-000000000046} +' Core of the ApplicationHandler framework: application start and shutdown, application name/version, logging, extension mechanism via events (extensions: ApplicationHandler_*) ' '--------------------------------------------------------------------------------------- ' @@ -56,6 +58,11 @@ Public Enum ApplicationHandlerErrors End Enum ' API definitions +Private Const GCL_HBRBACKGROUND As Long = -10 +Private Const RDW_INVALIDATE As Long = &H1 +Private Const RDW_ERASE As Long = &H4 +Private Const SYSCOLOR_COLOR_APPWORKSPACE As Long = 12 + #If VBA7 Then Private Declare PtrSafe Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _ @@ -65,10 +72,10 @@ Private Declare PtrSafe Function FindWindowEx Lib "user32.dll" Alias "FindWindow Private Declare PtrSafe Function CreateSolidBrush Lib "gdi32.dll" (ByVal CrColor As Long) As Long Private Declare PtrSafe Function SetClassLong Lib "user32" Alias "SetClassLongA" ( _ - ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long + ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare PtrSafe Function RedrawWindow Lib "user32" ( _ - ByVal hwnd As Long, LprcUpdate As Any, _ + ByVal Hwnd As Long, LprcUpdate As Any, _ ByVal HrgnUpdate As Long, ByVal FuRedraw As Long) As Long Private Declare PtrSafe Function GetSysColor Lib "user32" (ByVal NumIndex As Long) As Long @@ -82,10 +89,10 @@ Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _ Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal CrColor As Long) As Long Private Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" ( _ - ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long + ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function RedrawWindow Lib "user32" ( _ - ByVal hwnd As Long, LprcUpdate As Any, _ + ByVal Hwnd As Long, LprcUpdate As Any, _ ByVal HrgnUpdate As Long, ByVal FuRedraw As Long) As Long Private Declare Function GetSysColor Lib "user32" (ByVal Index As Long) As Long @@ -107,13 +114,15 @@ Private m_AppDb As DAO.Database ' Replacement for CurrentDb or Code Private m_ApplicationName As String ' Application name cache (short) Private m_ApplicationFullName As String ' Application name cache (long) -Private m_APPLICATIONVERSION As String ' Version number to be displayed +Private m_ApplicationVersion As String ' Version number to be displayed Private m_TransferValue As Variant Private m_PublicPath As String ' Default directory for file explorer Private m_ApplicationStartFormName As String ' Form that is opened in Start method +Private m_CustomMDIBackgroundColor As Long + 'Events Public Event BeforeDispose(ByRef ResumeMode As ApplicationHandlerResumeModes, ByRef ResumeMessage As Variant) Public Event AfterDispose(ByRef ResumeMode As ApplicationHandlerResumeModes, ByRef ResumeMessage As Variant) @@ -207,6 +216,9 @@ End Sub ' ' Application start ' +' Parameters: +' ResumeMessage - (ByRef) message returned by the extensions handling the start +' ' Returns: ' Boolean - true = success ' @@ -336,7 +348,7 @@ Public Property Let ApplicationFullName(ByVal AppName As String) End Property '--------------------------------------------------------------------------------------- -' Property: ApplicationVersion +' Property: Version '--------------------------------------------------------------------------------------- ' ' Application version @@ -344,23 +356,23 @@ End Property '--------------------------------------------------------------------------------------- Public Property Get Version() As String - If Len(m_APPLICATIONVERSION) = 0 Then ' ... aus Properties lesen? + If Len(m_ApplicationVersion) = 0 Then ' ... aus Properties lesen? '/** ' @todo Versionskennung aus DB-Eigenschaften bzw. aus den Dateieigenschaften lesen '**/ - m_APPLICATIONVERSION = "" + m_ApplicationVersion = "" End If - Version = m_APPLICATIONVERSION + Version = m_ApplicationVersion End Property Public Property Let Version(ByVal AppVersion As String) - m_APPLICATIONVERSION = AppVersion + m_ApplicationVersion = AppVersion End Property '--------------------------------------------------------------------------------------- -' Property: ApplicationStartForm +' Property: ApplicationStartFormName '--------------------------------------------------------------------------------------- ' ' Form opened in the method @@ -477,6 +489,7 @@ Private Sub SetAppDbProperty(ByVal PropName As String, ByVal PropType As Long, B Set db = AppDb Set PropCol = db.Properties + PropCol.Refresh If DbPropertyExists(PropCol, PropName) Then If Len(PropValue) = 0 Or IsNull(PropValue) Then db.Properties.Delete PropName diff --git a/access-add-in/source/modules/ApplicationHandler_AppFile.cls b/access-add-in/source/modules/ApplicationHandler_AppFile.cls index bc9b8e1..c6f7447 100644 --- a/access-add-in/source/modules/ApplicationHandler_AppFile.cls +++ b/access-add-in/source/modules/ApplicationHandler_AppFile.cls @@ -9,7 +9,7 @@ Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Attribute VB_Description = "Erweiterung für ApplicationHandler-Klasse: Anwendungsspezifische Dateien verwalten" '--------------------------------------------------------------------------------------- -' Class: base.ApplicationHandler_File +' Class: base.ApplicationHandler_AppFile '--------------------------------------------------------------------------------------- ' ' Extension for ApplicationHandler class: manage application-specific files @@ -19,7 +19,10 @@ Attribute VB_Description = "Erweiterung für ApplicationHandler-Klasse: Anwendun ' ' Remarks: ' Activation in the _config_Application module: -' ExtensionsCollectionReferenz.Add New ApplicationHandler_AppFile +' +' (start code) +' ExtensionsCollectionReferenz.Add New ApplicationHandler_AppFile +' (end) ' '--------------------------------------------------------------------------------------- @@ -30,6 +33,7 @@ Attribute VB_Description = "Erweiterung für ApplicationHandler-Klasse: Anwendun ' base/ApplicationHandler.cls ' api/winapi/WinApiFileInfo.cls ' DAO50{00025E01-0000-0000-C000-000000000046} +' ApplicationHandler extension: stores application files (e.g. icons, templates) in the table usys_AppFiles and extracts them to the file system ' '--------------------------------------------------------------------------------------- ' @@ -127,8 +131,10 @@ End Property ' Extract file from usys_AppFiles ' ' Parameters: -' FileID - Record identifier -' FileName - File name to be created +' FileID - Record identifier +' FileName - File name to be created +' ExtFilterFieldName - (optional) additional filter: field name +' ExtFilterValue - (optional) additional filter: value ' ' Returns: ' Boolean @@ -183,14 +189,16 @@ End Sub ' Function: SaveAppFile '--------------------------------------------------------------------------------------- ' -' Datei in usys_AppFiles speichern +' Save file in usys_AppFiles ' ' Parameters: -' FileID - Identifier in table -' FileName - File name to be created -' SaveVersion - (optional) Read version from file (e. g. from dll file) -' ExtFieldName - (optional) append additional data to data field: Field name -' ExtFieldValue - (optional) append additional data to data field: Value +' FileID - Identifier in table +' FileName - File name to be created +' SaveVersion - (optional) Read version from file (e. g. from dll file) +' ExtFieldName - (optional) append additional data to data field: Field name +' ExtFieldValue - (optional) append additional data to data field: Value +' ExtFilterFieldName - (optional) additional filter: field name (also stored in the record) +' ExtFilterValue - (optional) additional filter: value ' ' Returns: ' Boolean - True: File was saved in table diff --git a/access-add-in/source/modules/ApplicationHandler_ExtensionCollection.cls b/access-add-in/source/modules/ApplicationHandler_ExtensionCollection.cls index 4ddf2f1..b1e8e44 100644 --- a/access-add-in/source/modules/ApplicationHandler_ExtensionCollection.cls +++ b/access-add-in/source/modules/ApplicationHandler_ExtensionCollection.cls @@ -18,16 +18,17 @@ Attribute VB_Exposed = False ' ' Remarks: ' Use in the _config_Application module: -' -' Set m_Extensions = New ApplicationHandler_ExtensionCollection -' With m_Extensions -' Set .ApplicationHandler = oCurrentAppHandler ' -' ' Load extensions (e.g. ApplicationHandler_DbConnection): -' .Add New ApplicationHandler_DbConnection +' (start code) +' Set m_Extensions = New ApplicationHandler_ExtensionCollection +' With m_Extensions +' Set .ApplicationHandler = oCurrentAppHandler ' -' End With -' +' ' Load extensions (e.g. ApplicationHandler_DbConnection): +' .Add New ApplicationHandler_DbConnection +' +' End With +' (end) ' '--------------------------------------------------------------------------------------- @@ -36,15 +37,17 @@ Attribute VB_Exposed = False ' base/ApplicationHandler_ExtensionCollection.cls ' _codelib/license.bas ' base/ApplicationHandler.cls +' Collection that holds and initializes the ApplicationHandler extensions (Add, Dispose) ' '--------------------------------------------------------------------------------------- ' -Option Compare Text +Option Compare Database Option Explicit Private WithEvents m_ApplicationHandler As ApplicationHandler Attribute m_ApplicationHandler.VB_VarHelpID = -1 Private m_Extension As Collection +Private m_Disposed As Boolean '--------------------------------------------------------------------------------------- ' Property: Extensions @@ -109,6 +112,6 @@ On Error Resume Next Dispose End Sub -Private Sub m_ApplicationHandler_AfterDispose(ByRef ResumeMode As ApplicationHandlerResumeModes, ByRef ResumeMessage As Variant) +Private Sub m_ApplicationHandler_AfterDispose(ResumeMode As ApplicationHandlerResumeModes, ResumeMessage As Variant) Dispose End Sub diff --git a/access-add-in/source/modules/DaoHandler.cls b/access-add-in/source/modules/DaoHandler.cls index ad6b42e..ccd5e76 100644 --- a/access-add-in/source/modules/DaoHandler.cls +++ b/access-add-in/source/modules/DaoHandler.cls @@ -24,6 +24,8 @@ Attribute VB_Exposed = False ' _codelib/license.bas ' DAO50{00025E01-0000-0000-C000-000000000046} ' _test/data/dao/DaoHandlerTests.cls +' DAO data access: execute SQL and parameter queries, open recordsets, lookups and aggregates +' _examples/data/dao/DaoHandler_Beispiele.bas ' '--------------------------------------------------------------------------------------- ' @@ -174,7 +176,7 @@ End Property ' Execute SQL statement ' ' Parameters: -' CommandText - SQL statement (String) +' Query - SQL statement (String) ' Options - DAO.RecordsetOptionEnum ' ' Returns: @@ -369,7 +371,7 @@ End Function ' Function: ParamQueryDefSql '--------------------------------------------------------------------------------------- ' -' Temporäres QueryDef-Objekt ink. übergebenen Parameterwerten öffnen +' Open temporary QueryDef object incl. passed parameter values ' ' Parameters: ' ParamSqlText - SQL statement for the temporary QueryDef object @@ -403,9 +405,9 @@ End Function ' ' Parameters: ' Source - SQL statement or table or query name -' RecordsetType - DAO.RecordsetTypeEnum (Standard: dbOpenDynaset) -' RecordsetOptions - DAO.RecordsetOptionEnum (Standard: dbSeeChanges) -' LockEdit - DAO.LockTypeEnum (Standard: dbOptimistic) +' RecordsetType - DAO.RecordsetTypeEnum (Default: dbOpenDynaset) +' RecordsetOptions - DAO.RecordsetOptionEnum (Default: dbSeeChanges) +' LockEdit - DAO.LockTypeEnum (Default: dbOptimistic) ' ' Returns: ' DAO.Recordset @@ -448,9 +450,9 @@ End Function ' ' Parameters: ' ParamSqlText - SQL statement with parameters (parameter declaration) -' RecordsetType - DAO.RecordsetTypeEnum (Standard: dbOpenDynaset) -' RecordsetOptions - DAO.RecordsetOptionEnum (Standard: dbSeeChanges) -' LockEdit - DAO.LockTypeEnum (Standard: dbOptimistic) +' RecordsetType - DAO.RecordsetTypeEnum (Default: dbOpenDynaset) +' Options - DAO.RecordsetOptionEnum (Default: dbSeeChanges) +' LockEdit - DAO.LockTypeEnum (Default: dbOptimistic) ' QueryParams - Values in suitable order as ParamArray or as array ' or 2-dimensional parameter array (Array(n,1) ... x(n,0) = parameter name, x(n,1) = parameter value) ... generateable with GetParamDefArray or GetNamedParamDefArray ' @@ -639,7 +641,7 @@ End Function ' Creates 2-dimensional parameter array (e.g. for OpenRecordsetQueryDef) ' ' Parameters: -' ParamValues - Parameter pairs: alternating parameter index and parameter value +' ParamIndexAndValues - Parameter pairs: alternating parameter index and parameter value ' ' Returns: ' Variant (Array) @@ -684,10 +686,10 @@ End Function ' Parameters: ' QueryName - Name of the saved query ' QueryParams - Values in suitable order as ParamArray or as array -' or 2-dimensional parameter array (Array(n,1) ... x(n,0) = parameter name, x(n,1) = parameter value) ... generateable with GetParamDefArray or GetNamedParamDefArray' -' RecordsetType - DAO.RecordsetTypeEnum (Standard: dbOpenDynaset) -' RecordsetOptions - DAO.RecordsetOptionEnum (Standard: dbSeeChanges) -' LockEdit - DAO.LockTypeEnum (Standard: dbOptimistic) +' or 2-dimensional parameter array (Array(n,1) ... x(n,0) = parameter name, x(n,1) = parameter value) ... generateable with GetParamDefArray or GetNamedParamDefArray +' RecordsetType - DAO.RecordsetTypeEnum (Default: dbOpenDynaset) +' Options - DAO.RecordsetOptionEnum (Default: dbSeeChanges) +' LockEdit - DAO.LockTypeEnum (Default: dbOptimistic) ' ' Returns: ' DAO.Recordset @@ -727,15 +729,15 @@ End Function ' Function: OpenRecordsetQueryDef '--------------------------------------------------------------------------------------- ' -' Recordset von gespeicherter Abfrage (optional mit Parametern) öffnen +' Open recordset from saved query (optionally with parameters) ' ' Parameters: ' QdfRef - QueryDef reference ' QueryParams - Values in suitable order as ParamArray or as array -' or 2-dimensional parameter array (Array(n,1) ... x(n,0) = parameter name, x(n,1) = parameter value) ... generateable with GetParamDefArray or GetNamedParamDefArray' -' RecordsetType - DAO.RecordsetTypeEnum (Standard: dbOpenDynaset) -' RecordsetOptions - DAO.RecordsetOptionEnum (Standard: dbSeeChanges) -' LockEdit - DAO.LockTypeEnum (Standard: dbOptimistic) +' or 2-dimensional parameter array (Array(n,1) ... x(n,0) = parameter name, x(n,1) = parameter value) ... generateable with GetParamDefArray or GetNamedParamDefArray +' RecordsetType - DAO.RecordsetTypeEnum (Default: dbOpenDynaset) +' RecordsetOptions - DAO.RecordsetOptionEnum (Default: dbSeeChanges) +' LockEdit - DAO.LockTypeEnum (Default: dbOptimistic) ' ' Returns: ' DAO.Recordset @@ -865,6 +867,7 @@ End Function ' Expr - Field name or calculated expression (select part) ' Domain - Table, query or SQL expression for sub-query (FROM part) ' Criteria - (optional) Criteria string (WHERE part) +' Distinct - (optional) True: count distinct values of Expr ' ' Returns: ' Long @@ -1050,11 +1053,11 @@ End Function ' Function: InsertValuesReturnFieldValue '--------------------------------------------------------------------------------------- ' -' Ropen ecordset and append values, returns value of a defined data field +' Open recordset and append values, returns value of a defined data field ' ' Parameters: ' Source - Insert data source -' ReturnFieldNameOrIndex - Datenfeld für Wertrückgabe +' ReturnFieldNameOrIndex - Data field (name or index) for the return value ' FieldsAndValues - ParamArray: "Field1", Value1, "Field2", Value2, .... ' ' Returns: @@ -1072,7 +1075,7 @@ Private Function InsertRecordValuesArrayReturnFieldValue( _ ByVal Source As String, ByVal ReturnField As Variant, _ ByVal FieldsAndValues As Variant) As Variant - Dim lngNum As Long, i As Long, FieldIdx As Long + Dim lngNum As Long, lngAnz As Long, i As Long, anz As Long Dim FieldNames() As Variant, FieldValues() As Variant Dim rst As DAO.Recordset Dim ErrNo As Long, ErrDesc As String, ErrSource As String @@ -1083,11 +1086,11 @@ On Error GoTo HandleErr ReDim FieldNames(lngNum \ 2) ReDim FieldValues(lngNum \ 2) - FieldIdx = -1 + anz = 0 For i = 0 To (lngNum - 2) Step 2 - FieldIdx = FieldIdx + 1 - FieldNames(FieldIdx) = FieldsAndValues(i) - FieldValues(FieldIdx) = FieldsAndValues(i + 1) + FieldNames(anz) = FieldsAndValues(i) + FieldValues(anz) = FieldsAndValues(i + 1) + anz = anz + 1 Next i Set rst = Me.OpenRecordset(Source, dbOpenDynaset) @@ -1095,7 +1098,7 @@ On Error GoTo HandleErr .AddNew i = 0 - For i = 0 To FieldIdx + For i = 0 To (anz - 1) .Fields(FieldNames(i)) = FieldValues(i) Next i .Update @@ -1357,7 +1360,7 @@ End Function ' Function: CopyRecords '--------------------------------------------------------------------------------------- ' -' Recordset öffnen und Werte eines Datensatzes anfügen +' Open recordset and append values of a record ' ' Parameters: ' Source - Data source (table name or SQL statement) @@ -1394,9 +1397,8 @@ End Function '--------------------------------------------------------------------------------------- ' Function: CopyRecordsReturnFieldValue '--------------------------------------------------------------------------------------- -'/** -' -' Datensätze kopieren und Werte ändern +' +' Copy records and change values ' ' Parameters: ' Source - Data source (table name or SQL statement) @@ -1436,24 +1438,23 @@ Private Function CopyRecordsArrayReturnFieldValue(ByVal SqlSource As String, _ On Error GoTo HandleErr - Dim lngNum As Long, i As Long, iDS As Long, idx As Long + Dim lngNum As Long, lngAnz As Long, i As Long, iDS As Long, anz As Long Dim strCtl() As Variant, valCtl() As Variant Dim rst As Object - Dim lngLastCopyField As Long, rsCnt As Long, Start As Long + Dim lngLastCopyField As Long, dsAnz As Long, Start As Long Dim CopyFieldsAndValues() As Variant Dim ErrNo As Long, ErrDesc As String, ErrSource As String lngNum = UBound(UpdateFieldsAndValues) - LBound(UpdateFieldsAndValues) + 1 - + anz = 0 ReDim strCtl((lngNum \ 2) - 1) ReDim valCtl((lngNum \ 2) - 1) - idx = -1 For i = 0 To (lngNum - 2) Step 2 - idx = idx + 1 - strCtl(idx) = UpdateFieldsAndValues(i) - valCtl(idx) = UpdateFieldsAndValues(i + 1) + strCtl(anz) = UpdateFieldsAndValues(i) + valCtl(anz) = UpdateFieldsAndValues(i + 1) + anz = anz + 1 Next i Set rst = Me.OpenRecordset(SqlSource, dbOpenDynaset) @@ -1468,7 +1469,7 @@ On Error GoTo HandleErr With rst .MoveLast .MoveFirst - rsCnt = .RecordCount + dsAnz = .RecordCount If LastFeldID = 0 Then lngLastCopyField = .Fields.Count @@ -1478,7 +1479,7 @@ On Error GoTo HandleErr lngLastCopyField = LastFeldID End If - ReDim CopyFieldsAndValues(rsCnt, lngLastCopyField) + ReDim CopyFieldsAndValues(dsAnz, lngLastCopyField) If StartFeldID > 1 Then Start = StartFeldID - 1 Else Start = 0 @@ -1496,14 +1497,14 @@ On Error GoTo HandleErr .MoveLast 'Copy values - For iDS = 0 To (rsCnt - 1) + For iDS = 0 To (dsAnz - 1) .AddNew For i = Start To (lngLastCopyField - 1) If .Fields(i).Type <> dbBinary Then .Fields(i) = CopyFieldsAndValues(iDS, i) End If Next i - For i = 0 To idx + For i = 0 To (anz - 1) .Fields(strCtl(i)) = valCtl(i) Next i .Update diff --git a/access-add-in/source/modules/DaoTools.bas b/access-add-in/source/modules/DaoTools.bas index 0d09806..664e2c1 100644 --- a/access-add-in/source/modules/DaoTools.bas +++ b/access-add-in/source/modules/DaoTools.bas @@ -17,26 +17,26 @@ Attribute VB_Description = "Hilfsfunktionen für den Umgang mit DAO" ' _codelib/license.bas ' DAO50{00025E01-0000-0000-C000-000000000046} ' _test/data/dao/DaoToolsTests.cls +' DAO helper functions: check whether a table or query exists ' '--------------------------------------------------------------------------------------- ' -Option Compare Text +Option Compare Database Option Explicit -Option Private Module '--------------------------------------------------------------------------------------- ' Function: TableDefExists '--------------------------------------------------------------------------------------- -'/** -' -' Prüft ob eine Tabelle (TableDef) vorhanden ist -' -' Name der Tabelle -' DAO.Database-Referenz (falls keine angegeben wurde, wird CodeDb verwendet) -' Boolean -' -' -'**/ +' +' Checks whether a table (TableDef) exists +' +' Parameters: +' TableDefName - Name of the table +' DbRef - DAO.Database reference (if not specified, CodeDb is used) +' +' Returns: +' Boolean +' '--------------------------------------------------------------------------------------- Public Function TableDefExists(ByVal TableDefName As String, _ Optional ByVal DbRef As DAO.Database = Nothing) As Boolean @@ -50,16 +50,16 @@ End Function '--------------------------------------------------------------------------------------- ' Function: QueryDefExists '--------------------------------------------------------------------------------------- -'/** -' -' Prüft ob eine Abfrage (QueryDef) vorhanden ist -' -' Name der Abfrage -' DAO.Database-Referenz (falls keine angegeben wurde, wird CodeDb verwendet) -' Boolean -' -' -'**/ +' +' Checks whether a query (QueryDef) exists +' +' Parameters: +' QueryDefName - Name of the query +' DbRef - DAO.Database reference (if not specified, CodeDb is used) +' +' Returns: +' Boolean +' '--------------------------------------------------------------------------------------- Public Function QueryDefExists(ByVal QueryDefName As String, _ Optional ByVal DbRef As DAO.Database = Nothing) As Boolean diff --git a/access-add-in/source/modules/FileTools.bas b/access-add-in/source/modules/FileTools.bas index 8be8962..b8710c6 100644 --- a/access-add-in/source/modules/FileTools.bas +++ b/access-add-in/source/modules/FileTools.bas @@ -16,6 +16,7 @@ Attribute VB_Description = "Funktionen für Dateioperationen" ' file/FileTools.bas ' _codelib/license.bas ' _test/file/FileToolsTests.cls +' File and folder functions: file/folder selection dialogs, temp path and temp file names, path handling (UNC, relative/absolute paths, file name, extension), create folders, existence checks, zip files, open files with the associated application ' '--------------------------------------------------------------------------------------- ' @@ -26,12 +27,12 @@ Option Private Module #If USELOCALIZATION_DE = 1 Then Private Const SELECTBOX_FILE_DIALOG_TITLE As String = "Datei auswählen" Private Const SELECTBOX_FOLDER_DIALOG_TITLE As String = "Ordner auswählen" -Private Const SELECTBOX_OPENTITLE As String = "auswählen" +Private Const SELECTBOX_OPENTITLE As String = "Auswählen" Private Const FILTERSTRING_ALL_FILES As String = "Alle Dateien (*.*)" #Else Private Const SELECTBOX_FILE_DIALOG_TITLE As String = "Select file" Private Const SELECTBOX_FOLDER_DIALOG_TITLE As String = "Select folder" -Private Const SELECTBOX_OPENTITLE As String = "auswählen" +Private Const SELECTBOX_OPENTITLE As String = "Select" Private Const FILTERSTRING_ALL_FILES As String = "All Files (*.*)" #End If @@ -43,8 +44,6 @@ Private Const SE_ERR_NOASSOC As Long = 31 Private Const VbaErrNo_FileNotFound As Long = 53 -#If VBA7 Then - Private Declare PtrSafe Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" ( _ ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long @@ -58,38 +57,14 @@ Private Declare PtrSafe Function API_GetTempFilename Lib "kernel32" Alias "GetTe ByVal wUnique As Long, _ ByVal lpTempFileName As String) As Long -Private Declare PtrSafe Function API_ShellExecuteA Lib "shell32.dll" ( _ - ByVal hwnd As LongPtr, _ +Private Declare PtrSafe Function API_ShellExecuteA Lib "shell32.dll" Alias "ShellExecuteA" ( _ + ByVal Hwnd As LongPtr, _ ByVal lOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long -#Else - -Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" ( _ - ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long - -Private Declare Function API_GetTempPath Lib "kernel32" Alias "GetTempPathA" ( _ - ByVal nBufferLength As Long, _ - ByVal lpBuffer As String) As Long - -Private Declare Function API_GetTempFilename Lib "kernel32" Alias "GetTempFileNameA" ( _ - ByVal lpszPath As String, _ - ByVal lpPrefixString As String, _ - ByVal wUnique As Long, _ - ByVal lpTempFileName As String) As Long - -Private Declare Function API_ShellExecuteA Lib "shell32.dll" ( _ - ByVal hwnd As Long, _ - ByVal lOperation As String, _ - ByVal lpFile As String, _ - ByVal lpParameters As String, _ - ByVal lpDirectory As String, _ - ByVal nShowCmd As Long) As Long - -#End If '--------------------------------------------------------------------------------------- ' Function: SelectFile @@ -98,11 +73,11 @@ Private Declare Function API_ShellExecuteA Lib "shell32.dll" ( _ ' Select file using dialogue ' ' Parameters: -' InitDir - Initial Folder -' DlgTitle - Title of dialogue -' FilterString - Filter settings - Example: "(*.*)" oder "All (*.*)|text files (*.txt)|Images (*.png;*.jpg;*.gif) -' MultiSelect - Multi-selection -' ViewMode - View mode (0: Detail view, 1: Preview, 2: Properties, 3: List, 4: Thumbnail, 5: Large symbols, 6: Small symbols) +' InitialDir - Initial folder +' DlgTitle - Title of dialogue +' FilterString - Filter settings - Example: "(*.*)" or "All (*.*)|text files (*.txt)|Images (*.png;*.jpg;*.gif) +' MultiSelectEnabled - Multi-selection +' ViewMode - View mode (0: Detail view, 1: Preview, 2: Properties, 3: List, 4: Thumbnail, 5: Large symbols, 6: Small symbols) ' ' Returns: ' String - in case of multiple selection, the files are separated by chr(9)) @@ -125,11 +100,11 @@ End Function ' Folder selection dialogue ' ' Parameters: -' InitDir - Initial Folder -' DlgTitle - Title of dialogue -' FilterString - Filter settings, Default:* -' MultiSelect - Multi-selection -' ViewMode - View mode (0: Detail view, 1: Preview, 2: Properties, 3: List, 4: Thumbnail, 5: Large symbols, 6: Small symbols) +' InitialDir - Initial folder +' DlgTitle - Title of dialogue +' FilterString - Filter settings, Default: * +' MultiSelectEnabled - Multi-selection +' ViewMode - View mode (0: Detail view, 1: Preview, 2: Properties, 3: List, 4: Thumbnail, 5: Large symbols, 6: Small symbols) ' ' Returns: ' String - in case of multiple selection, folders are separated by chr(9)) @@ -156,6 +131,7 @@ Private Function WizHook_GetFileName( _ Optional ByVal SelectFolderFlag As Boolean = False, _ Optional ByVal AppName As String) As String + 'Summary of WizHook.GetFileName parameters: http://www.team-moeller.de/?Tipps_und_Tricks:Wizhook-Objekt:GetFileName 'View 0: Detailansicht ' 1: Vorschauansicht @@ -269,9 +245,9 @@ End Property ' Generate temporary file name ' ' Parameters: -' PathToUse -' FilePrefix -' FileExtension +' PathToUse - (optional) Folder for the file (Default: Temp folder) +' FilePrefix - (optional) Prefix of the file name +' FileExtension - (optional) File extension ' ' Returns: ' String @@ -356,7 +332,7 @@ End Function ' Extract file name from complete path specification ' ' Parameters: -' FullPath">File name incl. directory +' FullPath - File name incl. directory ' ' Returns: ' String @@ -589,8 +565,8 @@ End Function ' Creates a complete path specification from relative path specification and "base directory". ' ' Parameters: -' RelativPath">relative path -' BaseDir">Base directory +' RelativPath - Relative path +' BaseDir - Base directory ' ' Returns: ' String @@ -646,9 +622,10 @@ End Function ' Creates a relative path from the complete path specification and source directory ' ' Parameters: -' FullPath - Full path specification -' BaseDir - Base directory -' RelativePrefix - Add ".\" as relative path identifier +' FullPath - Full path specification +' BaseDir - Base directory +' EnableRelativePrefix - Add ".\" as relative path identifier +' DisableDecreaseBaseDir - True: do not go up the base directory (no "..\" in result) ' ' Returns: ' String @@ -842,32 +819,68 @@ End Function ' Open file with API ShellExecute ' ' Parameters: -' FileName - File path or file name +' FilePath - File path or file name +' ReadOnlyMode - (optional) not used yet +' DefaultFileFolderIfFileNameOnly - (optional) Folder used if FilePath contains no folder ' ' Returns: ' Boolean ' '--------------------------------------------------------------------------------------- -Public Function OpenFile(ByVal FilePath As String) As Boolean +Public Function OpenFile(ByVal FilePath As String, Optional ByVal ReadOnlyMode As Boolean = False, _ + Optional ByVal DefaultFileFolderIfFileNameOnly As String = vbNullString) As Boolean Const FileNotFoundErrorTextTemplate As String = "File '{FilePath}' not found." Dim FileNotFoundErrorText As String + Dim FilePath2Open As String - If Len(VBA.Dir(FilePath)) = 0 Then + If Len(DefaultFileFolderIfFileNameOnly) > 0 Then + FilePath2Open = BuildFullFileName(FilePath, DefaultFileFolderIfFileNameOnly) + Else + FilePath2Open = FilePath + End If + + If Len(VBA.Dir(FilePath2Open)) = 0 Then #If USELOCALIZATION = 1 Then - FileNotFoundErrorText = Replace(L10n.Text(FileNotFoundErrorTextTemplate), "{FilePath}", FilePath) + FileNotFoundErrorText = Replace(L10n.Text(FileNotFoundErrorTextTemplate), "{FilePath}", FilePath2Open) #Else - FileNotFoundErrorText = Replace(FileNotFoundErrorTextTemplate, "{FilePath}", FilePath) + FileNotFoundErrorText = Replace(FileNotFoundErrorTextTemplate, "{FilePath}", FilePath2Open) #End If Err.Raise VbaErrNo_FileNotFound, "FileTools.OpenFile", FileNotFoundErrorText Exit Function End If - OpenFile = ShellExecute(FilePath, "open") + OpenFile = ShellExecute(FilePath2Open, "open") End Function +Public Function BuildFullFileName(ByVal FileName As String, ByVal DefaultFileFolderIfFileNameOnly As String) As String + + If Len(DefaultFileFolderIfFileNameOnly) = 0 Then + BuildFullFileName = FileName + Exit Function + End If + + If Left(FileName, 2) = "\\" Then 'Win-Share + BuildFullFileName = FileName + Exit Function + End If + + If Mid(FileName, 2, 1) = ":" Then 'Laufwerksbuchstabe + BuildFullFileName = FileName + Exit Function + End If + + If Left(FileName, 1) <> "\" And Right(DefaultFileFolderIfFileNameOnly, 1) <> "\" Then + DefaultFileFolderIfFileNameOnly = DefaultFileFolderIfFileNameOnly & "\" + End If + + BuildFullFileName = DefaultFileFolderIfFileNameOnly & FileName + +End Function + + '--------------------------------------------------------------------------------------- ' Function: OpenFilePath '--------------------------------------------------------------------------------------- @@ -875,7 +888,7 @@ End Function ' Open folder with API ShellExecute ' ' Parameters: -' FilePath - folder path or file name +' FolderPath - Folder path or file name ' ' Returns: ' Boolean @@ -907,6 +920,7 @@ Private Function ShellExecute(ByVal FilePath As String, _ Const FileNotFoundErrorTextTemplate As String = "File '{FilePath}' not found." Dim FileNotFoundErrorText As String Dim Ret As Long + Dim Directory As String Dim DeskWin As Long If Len(FilePath) = 0 Then @@ -929,6 +943,14 @@ Private Function ShellExecute(ByVal FilePath As String, _ ElseIf Ret = SE_ERR_NOASSOC Then ShellExecute = False Exit Function +' ToDo: "Öffnen mit"-Dialog verwenden: + 'Wenn die Dateierweiterung noch nicht bekannt ist... + 'wird der "Öffnen mit..."-Dialog angezeigt. +' Directory = Space$(260) +' Ret = GetSystemDirectory(Directory, Len(Directory)) +' Directory = Left$(Directory, Ret) +' Call ShellExecuteA(DeskWin, vbNullString, "RUNDLL32.EXE", "shell32.dll, OpenAs_RunDLL " & _ +' FilePath, Directory, vbNormalFocus) End If ShellExecute = True diff --git a/access-add-in/source/modules/NetComDomain.cls b/access-add-in/source/modules/NetComDomain.cls index a880c86..0f10d91 100644 --- a/access-add-in/source/modules/NetComDomain.cls +++ b/access-add-in/source/modules/NetComDomain.cls @@ -8,17 +8,23 @@ Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False '--------------------------------------------------------------------------------------- -' Class Module: NetComDomain +' Class: com.NetComDomain '--------------------------------------------------------------------------------------- -'/** -' \author Josef Poetzl -' \brief Start .NET COM dll without registration (hosts the .NET Framework 4 CLR) -' \ingroup COM -'**/ +' +' Use a .NET COM dll without registration (hosts the .NET Framework 4 CLR) +' +' Author: +' Josef Poetzl +' +'--------------------------------------------------------------------------------------- + '--------------------------------------------------------------------------------------- ' -' COM/NetComDomain.cls +' com/NetComDomain.cls ' _codelib/license.bas +' stdole20{00020430-0000-0000-C000-000000000046} +' _examples/com/NetComDomain_Example_ShowWinForm_Minimal.bas +' Creates objects from a .NET COM library without registration (hosts the .NET 4 CLR, no references needed) ' '--------------------------------------------------------------------------------------- Option Compare Text @@ -80,17 +86,17 @@ Private m_DefaultNameSpace As String '--------------------------------------------------------------------------------------- ' Function: CreateObject '--------------------------------------------------------------------------------------- -'/** -' +' ' Creates a new instance of a class from a .NET COM dll -' -' Name of the class without namespace -' Namespace of the class -' Absolute path of the .NET COM dll -' Object -' -' -'**/ +' +' Parameters: +' ClassIdentifier - Name of the class without namespace +' DefaultNameSpace - Namespace containing the class +' LibraryFile - Absolute path of the .NET COM dll +' +' Returns: +' Object +' '--------------------------------------------------------------------------------------- Public Function CreateObject(ByVal ClassIdentifier As String, _ Optional ByVal DefaultNameSpace As String = vbNullString, _ @@ -222,14 +228,15 @@ Private Sub ReleaseComPointer(ByRef Pointer As LongPtr) End If End Sub -' Wraps an IUnknown pointer into an Object variable. The caller still owns its own reference. +' Wraps an IUnknown pointer into an Object variable (QueryInterface for IDispatch). +' The caller still owns its own reference. Private Function ObjectFromPointer(ByVal Pointer As LongPtr) As Object - Dim Unknown As Object + Dim Unknown As stdole.IUnknown Dim NullPointer As LongPtr CopyMemory Unknown, Pointer, PointerSize ' no AddRef - Set ObjectFromPointer = Unknown ' AddRef + Set ObjectFromPointer = Unknown ' QueryInterface(IDispatch) incl. AddRef CopyMemory Unknown, NullPointer, PointerSize ' no Release when Unknown goes out of scope End Function diff --git a/access-add-in/source/modules/SqlTools.cls b/access-add-in/source/modules/SqlTools.cls index 2e80fdd..c5a1f2e 100644 --- a/access-add-in/source/modules/SqlTools.cls +++ b/access-add-in/source/modules/SqlTools.cls @@ -10,6 +10,7 @@ Attribute VB_Exposed = False '--------------------------------------------------------------------------------------- ' Class: data.sql.SqlTools '--------------------------------------------------------------------------------------- +' ' Functions to build sql strings ' ' Author: @@ -31,6 +32,8 @@ Attribute VB_Exposed = False ' data/SqlTools.bas ' _test/data/SqlToolsTests.cls ' _test/data/SqlToolsBuildCriteriaTests.cls +' Converts values to SQL literals (text, number, date, boolean) for DAO or T-SQL and builds criteria safely +' _examples/data/SqlTools_BuildCriteria_Examples.bas ' '--------------------------------------------------------------------------------------- ' @@ -54,9 +57,13 @@ Private Const SQL_DEFAULT_WILDCARD As String = "%" ' % = default value, Private Const SqlAndConcatString As String = " And " Private Const SqlOrConcatString As String = " Or " -Private m_SqlDateFormat As String -Private m_SqlBooleanTrueString As String -Private m_SqlWildCardString As String +Private Type SqlFormatSettings + SqlDateFormat As String + SqlBooleanTrueString As String + SqlWildCardString As String +End Type + +Private m_SqlFormat As SqlFormatSettings Private Const ResultTextIfNull As String = "Null" @@ -90,9 +97,61 @@ Public Enum SqlLogicalOperator SQL_CommaSeparator = 3 End Enum +Public Enum SqlDialect + SQL_Custom = 0 + SQL_DAO = 1 + SQL_TSQL = 2 +End Enum + '################################## ' Group: Class support +'--------------------------------------------------------------------------------------- +' Function: FromDialect +'--------------------------------------------------------------------------------------- +' +' Create a new instance with basic settings of the selected dialect +' +' Parameters: +' +' UseDialect - use setting of dialect (as base) +' NewSqlDateFormat - use this date format instead of base dialect +' NewSqlBooleanTrueString - use this text for true instead of base dialect +' NewSqlWildCardString - use this wildcard string instead of base dialect +' +' Returns: +' +' SqlTools instance with config form base +' +' See Also: +' NewInstance +' +'--------------------------------------------------------------------------------------- +Public Function FromDialect(ByVal UseDialect As SqlDialect, _ + Optional ByVal NewSqlDateFormat As String = SQL_DEFAULT_DATEFORMAT, _ + Optional ByVal NewSqlBooleanTrueString As String = SQL_DEFAULT_BOOLTRUESTRING, _ + Optional ByVal NewSqlWildCardString As String = SQL_DEFAULT_WILDCARD) As SqlTools + + Dim NewSlqToolsInstance As SqlTools + + Select Case UseDialect + Case SqlDialect.SQL_DAO + Set NewSlqToolsInstance = Me.DAO + Case SqlDialect.SQL_TSQL + Set NewSlqToolsInstance = Me.TSql + Case Else + Set NewSlqToolsInstance = Me.Clone + End Select + + If Len(NewSqlDateFormat) > 0 Then NewSlqToolsInstance.SqlDateFormat = NewSqlDateFormat + If Len(NewSqlBooleanTrueString) > 0 Then NewSlqToolsInstance.SqlBooleanTrueString = NewSqlBooleanTrueString + If Len(NewSqlWildCardString) > 0 Then NewSlqToolsInstance.SqlWildCardString = NewSqlWildCardString + + Set FromDialect = NewSlqToolsInstance + +End Function + + '--------------------------------------------------------------------------------------- ' Function: Clone '--------------------------------------------------------------------------------------- @@ -117,7 +176,6 @@ Public Function Clone(Optional ByVal NewSqlDateFormat As String = SQL_DEFAULT_DA Optional ByVal NewSqlBooleanTrueString As String = SQL_DEFAULT_BOOLTRUESTRING, _ Optional ByVal NewSqlWildCardString As String = SQL_DEFAULT_WILDCARD) As SqlTools - If Len(NewSqlDateFormat) = 0 Then NewSqlDateFormat = Me.SqlDateFormat If Len(NewSqlBooleanTrueString) = 0 Then NewSqlBooleanTrueString = Me.SqlBooleanTrueString If Len(NewSqlWildCardString) = 0 Then NewSqlWildCardString = Me.SqlWildCardString @@ -132,6 +190,14 @@ End Function ' ' Create a new instance ' +' Parameters: +' NewSqlDateFormat - Output string format for date values +' NewSqlBooleanTrueString - Output string for boolean value True +' NewSqlWildCardString - Wildcard string (e.g. * .. DAO, % .. T-SQL) +' +' Returns: +' SqlTools +' '--------------------------------------------------------------------------------------- Public Function NewInstance(ByVal NewSqlDateFormat As String, _ ByVal NewSqlBooleanTrueString As String, _ @@ -150,6 +216,66 @@ Public Function NewInstance(ByVal NewSqlDateFormat As String, _ End Function +'--------------------------------------------------------------------------------------- +' Function: InitSqlDialect +'--------------------------------------------------------------------------------------- +' +' Config sql text output format for specific sql dialect +' +' Parameters: +' UseDialect - SQL dialect (SQL_DAO, SQL_TSQL, SQL_Custom) +' NewSqlDateFormat - Output string format for date values +' NewSqlBooleanTrueString - Output string for boolean value True +' NewSqlWildCardString - Wildcard string (e.g. * .. DAO, % .. T-SQL) +' +'--------------------------------------------------------------------------------------- +Friend Sub InitSqlDialect(ByVal UseDialect As SqlDialect, _ + Optional ByVal NewSqlDateFormat As String = SQL_DEFAULT_DATEFORMAT, _ + Optional ByVal NewSqlBooleanTrueString As String = SQL_DEFAULT_BOOLTRUESTRING, _ + Optional ByVal NewSqlWildCardString As String = SQL_DEFAULT_WILDCARD) + + Dim SqlFormat As SqlFormatSettings + + Select Case UseDialect + Case SqlDialect.SQL_DAO + SqlFormat = DaoSqlFormat + Case SqlDialect.SQL_TSQL + SqlFormat = TSqlSqlFormat + Case Else + ' set nothing => use NewSql* parameter + End Select + + If Len(NewSqlDateFormat) > 0 Then SqlFormat.SqlDateFormat = NewSqlDateFormat + If Len(NewSqlBooleanTrueString) > 0 Then SqlFormat.SqlBooleanTrueString = NewSqlBooleanTrueString + If Len(NewSqlWildCardString) > 0 Then SqlFormat.SqlWildCardString = NewSqlWildCardString + + InitSqlFormat SqlFormat.SqlDateFormat, SqlFormat.SqlBooleanTrueString, SqlFormat.SqlWildCardString + + +End Sub + +'--------------------------------------------------------------------------------------- +' Function: InitSqlFormat +'--------------------------------------------------------------------------------------- +' +' Config sql text output format for specific sql dialect +' +' Parameters: +' +' SqlDateFormat - output string format for date values +' SqlBooleanTrueString - output string format for boolean values +' SqlWildCardString - wildcard string (e.g. * .. dao, % .. T-SQL) +' +'--------------------------------------------------------------------------------------- +Friend Sub InitSqlFormat(ByVal SqlDateFormat As String, _ + ByVal SqlBooleanTrueString As String, _ + ByVal SqlWildCardString As String) + + Me.SqlDateFormat = SqlDateFormat + Me.SqlBooleanTrueString = SqlBooleanTrueString + Me.SqlWildCardString = SqlWildCardString + +End Sub '################################## ' Group: SQL dialect preferences @@ -162,7 +288,21 @@ End Function ' '--------------------------------------------------------------------------------------- Public Property Get DAO() As SqlTools - Set DAO = Me.NewInstance("\#yyyy-mm-dd hh:nn:ss\#", "True", "*") + With DaoSqlFormat + Set DAO = Me.NewInstance(.SqlDateFormat, .SqlBooleanTrueString, .SqlWildCardString) + End With +End Property + +Private Property Get DaoSqlFormat() As SqlFormatSettings + + Dim SqlFormat As SqlFormatSettings + + SqlFormat.SqlDateFormat = "\#yyyy-mm-dd hh:nn:ss\#" + SqlFormat.SqlBooleanTrueString = "True" + SqlFormat.SqlWildCardString = "*" + + DaoSqlFormat = SqlFormat + End Property '--------------------------------------------------------------------------------------- @@ -173,7 +313,21 @@ End Property ' '--------------------------------------------------------------------------------------- Public Property Get TSql() As SqlTools - Set TSql = Me.NewInstance("'yyyymmdd hh:nn:ss'", "1", "%") + With TSqlSqlFormat + Set TSql = Me.NewInstance(.SqlDateFormat, .SqlBooleanTrueString, .SqlWildCardString) + End With +End Property + +Private Property Get TSqlSqlFormat() As SqlFormatSettings + + Dim SqlFormat As SqlFormatSettings + + SqlFormat.SqlDateFormat = "'yyyymmdd hh:nn:ss'" + SqlFormat.SqlBooleanTrueString = "1" + SqlFormat.SqlWildCardString = "%" + + TSqlSqlFormat = SqlFormat + End Property ' Configuration for SQL dialect @@ -186,15 +340,15 @@ End Property ' '--------------------------------------------------------------------------------------- Public Property Get SqlWildCardString() As String - If Len(m_SqlWildCardString) > 0 Then - SqlWildCardString = m_SqlWildCardString + If Len(m_SqlFormat.SqlWildCardString) > 0 Then + SqlWildCardString = m_SqlFormat.SqlWildCardString Else SqlWildCardString = SQL_DEFAULT_WILDCARD End If End Property Public Property Let SqlWildCardString(ByVal NewValue As String) - m_SqlWildCardString = NewValue + m_SqlFormat.SqlWildCardString = NewValue End Property '--------------------------------------------------------------------------------------- @@ -205,15 +359,15 @@ End Property ' '--------------------------------------------------------------------------------------- Public Property Get SqlDateFormat() As String - If Len(m_SqlDateFormat) > 0 Then - SqlDateFormat = m_SqlDateFormat + If Len(m_SqlFormat.SqlDateFormat) > 0 Then + SqlDateFormat = m_SqlFormat.SqlDateFormat Else SqlDateFormat = SQL_DEFAULT_DATEFORMAT End If End Property Public Property Let SqlDateFormat(ByVal NewValue As String) - m_SqlDateFormat = NewValue + m_SqlFormat.SqlDateFormat = NewValue End Property '--------------------------------------------------------------------------------------- @@ -224,15 +378,15 @@ End Property ' '--------------------------------------------------------------------------------------- Public Property Get SqlBooleanTrueString() As String - If Len(m_SqlBooleanTrueString) > 0 Then - SqlBooleanTrueString = m_SqlBooleanTrueString + If Len(m_SqlFormat.SqlBooleanTrueString) > 0 Then + SqlBooleanTrueString = m_SqlFormat.SqlBooleanTrueString Else SqlBooleanTrueString = SQL_DEFAULT_BOOLTRUESTRING End If End Property Public Property Let SqlBooleanTrueString(ByVal NewValue As String) - m_SqlBooleanTrueString = NewValue + m_SqlFormat.SqlBooleanTrueString = NewValue End Property '################################## @@ -245,11 +399,13 @@ End Property ' Create SQL criteria string ' ' Parameters: -' FieldName - Field name in the data source to be filtered -' RelationalOperator - Relational operator (=, <=, etc.) -' FilterValue - Filter value (can be a single value or an array of values) -' FilterValue2 - Optional 2nd filter value (for Between) -' IgnoreValue - The value for which no filter condition is to be created. (Array transfer of values possible) +' FieldName - Field name in the data source to be filtered +' FieldDataType - Data type of the field (SqlFieldDataType) +' RelationalOperator - Relational operator (=, <=, etc.) +' FilterValue - Filter value (can be a single value or an array of values) +' FilterValue2 - Optional 2nd filter value (for Between) +' IgnoreValue - The value for which no filter condition is to be created. (Array transfer of values possible) +' DisableIgnoreNullValue - True: Null is not ignored as filter value (creates "Is Null" criteria) ' ' Returns: ' SQL criteria string @@ -308,17 +464,15 @@ Public Function BuildCriteria(ByVal FieldName As String, ByVal FieldDataType As Exit Function End If - If (RelationalOperator And SQL_SplitValueToArray) = SQL_SplitValueToArray Then - If InStr(1, FilterValue, ";") > 0 Then - FilterValue = Split(CharTrim(FilterValue, ";"), ";") - End If - RelationalOperator = RelationalOperator Xor SQL_SplitValueToArray + If TryBuildSplitToArrayCriteria(FieldName, FieldDataType, RelationalOperator, FilterValue, IgnoreValue, Criteria) Then + BuildCriteria = Criteria + Exit Function End If 'Special cases (part 2): If Not IsArray(FilterValue) Then - If FieldDataType = SQL_Numeric Then + If FieldDataType = SQL_Numeric Or FieldDataType = SQL_Date Then If FilterValue = "*" And RelationalOperator = SQL_Equal Then BuildCriteria = BuildCriteria(FieldName, FieldDataType, SQL_Not, Null, Null, 0, True) @@ -353,7 +507,8 @@ Public Function BuildCriteria(ByVal FieldName As String, ByVal FieldDataType As Exit Function End If - If (RelationalOperator And SQL_Like) = SQL_Like Then + If (RelationalOperator And SQL_Like) = SQL_Like Or (RelationalOperator And SQL_UseLikeBehavior) = SQL_UseLikeBehavior Then + If SqlWildCardString <> "*" Then If InStr(1, FilterValue, "*") > 0 Then FilterValue = Replace(FilterValue, "[*]", "@@@|||STAR|||@@@") @@ -361,6 +516,22 @@ Public Function BuildCriteria(ByVal FieldName As String, ByVal FieldDataType As FilterValue = Replace(FilterValue, "@@@|||STAR|||@@@", "*") End If End If + + If ((RelationalOperator And SQL_Add_WildCardPrefix) = 0) _ + And ((RelationalOperator And SQL_Add_WildCardSuffix) = 0) Then + + FilterValue = Replace(FilterValue, "[" & SqlWildCardString & "]", "@@@|||STAR|||@@@") + If InStr(1, FilterValue, SqlWildCardString) = 0 Then + RelationalOperator = RelationalOperator - SQL_Like + RelationalOperator = RelationalOperator Or SQL_Equal + FilterValue = Replace(FilterValue, "@@@|||STAR|||@@@", SqlWildCardString) + Else + FilterValue = Replace(FilterValue, "@@@|||STAR|||@@@", "[" & SqlWildCardString & "]") + End If + + End If + + End If If (RelationalOperator And SQL_Add_WildCardSuffix) = SQL_Add_WildCardSuffix Then @@ -371,7 +542,7 @@ Public Function BuildCriteria(ByVal FieldName As String, ByVal FieldDataType As End If If (RelationalOperator And SQL_Add_WildCardPrefix) = SQL_Add_WildCardPrefix Then - If (RelationalOperator And SQL_Like) = SQL_Like Then + If (RelationalOperator And SQL_Like) = SQL_Like Or (RelationalOperator And SQL_UseLikeBehavior) = SQL_UseLikeBehavior Then FilterValue = SqlWildCardString & FilterValue End If End If @@ -450,8 +621,8 @@ End Function ' String ' ' Example: -' strSQL = "select ... from tabelle where Feld = " & TextToSqlText("ab'cd") -' => strSQL = "select ... from tabelle where Feld = 'ab''cd'" +' strSQL = "select ... from TableName where FieldName = " & TextToSqlText("ab'cd") +' => strSQL = "select ... from TableName where FieldName = 'ab''cd'" ' '--------------------------------------------------------------------------------------- Public Function TextToSqlText(ByVal Value As Variant, _ @@ -519,7 +690,6 @@ End Function ' ' Parameters: ' Value - Value to convert -' FormatString - Date format (depends on DBMS!) ' ' Returns: ' String @@ -654,20 +824,20 @@ Private Function ConfigNumericSpecials( _ End Function -Private Function GetNextDigitNumber(ByVal Z As Variant, Optional AddToAbsoluteValue As Boolean = False) As Double +Private Function GetNextDigitNumber(ByVal NumValue As Variant, Optional AddToAbsoluteValue As Boolean = False) As Double Dim TestString As String - Dim KommaPos As Long - Dim digits As Long + Dim DecSignPos As Long + Dim Digits As Long Dim IsNegativ As Boolean Const AdditionalDecDigit As String = "1" Const AdditionalDecDigitKorr As Double = 0.1 - TestString = Trim(CStr(ConvertToNumeric(Replace(CStr(Z), "*", AdditionalDecDigit)))) + TestString = Trim(CStr(ConvertToNumeric(Replace(CStr(NumValue), "*", AdditionalDecDigit)))) If Left(TestString, 1) = "-" And (Not AddToAbsoluteValue) Then - GetNextDigitNumber = CDbl(Replace(CStr(Z), "*", vbNullString)) + GetNextDigitNumber = CDbl(Replace(CStr(NumValue), "*", vbNullString)) Exit Function End If @@ -675,26 +845,26 @@ Private Function GetNextDigitNumber(ByVal Z As Variant, Optional AddToAbsoluteVa IsNegativ = True End If - KommaPos = InStrRev(TestString, DecimalMarker) - If KommaPos = 0 Then ' next integer + DecSignPos = InStrRev(TestString, DecimalMarker) + If DecSignPos = 0 Then ' next integer If AddToAbsoluteValue And IsNegativ Then - GetNextDigitNumber = CDbl(Replace(CStr(Z), "*", vbNullString)) - 1 + GetNextDigitNumber = CDbl(Replace(CStr(NumValue), "*", vbNullString)) - 1 Else - GetNextDigitNumber = CDbl(Replace(CStr(Z), "*", vbNullString)) + 1 + GetNextDigitNumber = CDbl(Replace(CStr(NumValue), "*", vbNullString)) + 1 End If Exit Function End If - digits = Len(TestString) - KommaPos - 1 + Digits = Len(TestString) - DecSignPos - 1 If Left(TestString, 1) = "-" Then IsNegativ = True End If If AddToAbsoluteValue And IsNegativ Then - GetNextDigitNumber = CDbl(TestString) + AdditionalDecDigitKorr / 10 ^ digits - AdditionalDecDigitKorr / 10 ^ (digits - 1) + GetNextDigitNumber = CDbl(TestString) + AdditionalDecDigitKorr / 10 ^ Digits - AdditionalDecDigitKorr / 10 ^ (Digits - 1) Else - GetNextDigitNumber = CDbl(TestString) + (1 - AdditionalDecDigitKorr) / 10 ^ digits + GetNextDigitNumber = CDbl(TestString) + (1 - AdditionalDecDigitKorr) / 10 ^ Digits End If End Function @@ -702,11 +872,11 @@ End Function Private Property Get DecimalMarker() As String Static DecChar As String - Dim x As String + Dim CheckString As String If Len(DecChar) = 0 Then - x = Trim(CStr(1.2)) - DecChar = Mid(x, 2, 1) + CheckString = Trim(CStr(1.2)) + DecChar = Mid(CheckString, 2, 1) End If DecimalMarker = DecChar @@ -749,9 +919,9 @@ Friend Function GetRelationalOperatorString(ByRef RelationalOperator As SqlRelat op = RelationalOperator Xor SQL_Not - If op = SqlRelationalOperators.SQL_Equal Then ' => "=" zu "<>" .. null berücksichtigen? + If op = SqlRelationalOperators.SQL_Equal Then ' => "=" zu "<>" .. check for Null required? RelationalOperator = SQL_LessThan + SQL_GreaterThan - ElseIf op = SQL_GreaterThan + SQL_LessThan Then ' => "<>" zu "=" .. null berücksichtigen? + ElseIf op = SQL_GreaterThan + SQL_LessThan Then ' => "<>" zu "=" .. check for Null required? RelationalOperator = SQL_Equal Else RelationalOperator = RelationalOperator Xor SQL_Not @@ -797,16 +967,16 @@ Private Function TryBuildWildCardSuffixOrPreBuildParams(ByVal FieldName As Strin Dim Criteria1 As String Dim Criteria2 As String - If (RelationalOperator And SQL_Like) = SQL_Like Then + If (RelationalOperator And SQL_Like) = SQL_Like Or (RelationalOperator And SQL_UseLikeBehavior) = SQL_UseLikeBehavior Then FilterValue = FilterValue & SqlWildCardString - ElseIf (FieldDataType And SQL_Date) = SQL_Date Then + ElseIf FieldDataType = SQL_Date Then If (RelationalOperator And SQL_LessThan) = 0 Then ' no < therefore: >, >= or only = If (RelationalOperator And SQL_GreaterThan) = SQL_GreaterThan Then ' change nothing ... >= DataValue / SQL_Add_WildCardSuffix is not logical Else ' Consider the whole day ... FieldName >= DateValue and FieldName < DateAdd("d", 1, FilterValue)) Criteria = BuildCriteria(FieldName, FieldDataType, SQL_GreaterThan + SQL_Equal, FilterValue, , , False) & _ SqlAndConcatString & _ - BuildCriteria(FieldName, FieldDataType, SQL_LessThan, DateAdd("d", 1, CDate(CLng(FilterValue))), , , False) + BuildCriteria(FieldName, FieldDataType, SQL_LessThan, DateAdd("d", 1, CDate(CLng(CDate(FilterValue)))), , , False) TryBuildWildCardSuffixOrPreBuildParams = True Exit Function End If @@ -814,9 +984,9 @@ Private Function TryBuildWildCardSuffixOrPreBuildParams(ByVal FieldName As Strin If (RelationalOperator And SQL_Equal) = SQL_Equal Then RelationalOperator = RelationalOperator - SQL_Equal End If - FilterValue = DateAdd("d", 1, CDate(CLng(FilterValue))) + FilterValue = DateAdd("d", 1, CDate(CLng(CDate(FilterValue)))) End If - ElseIf (FieldDataType And SQL_Numeric) = SQL_Numeric Then + ElseIf FieldDataType = SQL_Numeric Then If (RelationalOperator And SQL_LessThan) = 0 Then ' no < daher: >, >= or only = If (RelationalOperator And SQL_GreaterThan) = SQL_GreaterThan Then If FilterValue Like "*[,.]*[*]" Then @@ -864,7 +1034,9 @@ Private Function TryBuildNumericSpecialCasesCriteria(ByRef FieldName As String, Const FilterValue2 As Variant = Null - FilterValue = Trim(FilterValue) + If VarType(FilterValue) = vbString Then + FilterValue = Trim(FilterValue) + End If If FilterValue Like "[0-9]*..*[0-9]*" Or FilterValue Like "[+-][0-9]*..*[0-9]*" Then TempArr = Split(FilterValue, "..") @@ -894,14 +1066,68 @@ Private Function TryBuildNumericSpecialCasesCriteria(ByRef FieldName As String, End Function -Private Function TryBuildArrayCriteria(ByRef FieldName As String, ByVal FieldDataType As SqlFieldDataType, _ + +Private Function TryBuildSplitToArrayCriteria(ByRef FieldName As String, ByVal FieldDataType As SqlFieldDataType, _ ByRef RelationalOperator As SqlRelationalOperators, _ ByRef FilterValue As Variant, _ ByRef IgnoreValue As Variant, _ ByRef Criteria As String) As Boolean + + Dim ValueSplitted As Boolean + Dim CriteriaConcatString As String + + If (RelationalOperator And SQL_SplitValueToArray) = SQL_SplitValueToArray Then + + RelationalOperator = RelationalOperator Xor SQL_SplitValueToArray + + If InStr(1, FilterValue, SqlOrConcatString, vbTextCompare) > 0 Then + FilterValue = Replace(FilterValue, SqlOrConcatString, ";") + End If + + If InStr(1, FilterValue, SqlAndConcatString, vbTextCompare) > 0 Then + FilterValue = Replace(FilterValue, SqlAndConcatString, "+") + End If + + If InStr(1, FilterValue, ";") > 0 Then + If InStr(1, FilterValue, "+") > 0 Then + RelationalOperator = RelationalOperator Or SQL_SplitValueToArray + End If + CriteriaConcatString = SqlOrConcatString + FilterValue = Split(CharTrim(FilterValue, ";"), ";") + ValueSplitted = True + ElseIf InStr(1, FilterValue, "+") > 0 Then + CriteriaConcatString = SqlAndConcatString + FilterValue = Split(CharTrim(FilterValue, "+"), "+") + ValueSplitted = True + End If + End If + + If ValueSplitted Then + + If CriteriaConcatString = SqlOrConcatString Then + If TryBuildInCriteria(FieldName, FieldDataType, RelationalOperator, FilterValue, IgnoreValue, Criteria) Then + Exit Function + End If + End If + + TryBuildSplitToArrayCriteria = TryBuildArrayCriteria(FieldName, FieldDataType, RelationalOperator, FilterValue, IgnoreValue, Criteria, CriteriaConcatString) + + End If + +End Function + + +Private Function TryBuildArrayCriteria(ByRef FieldName As String, ByVal FieldDataType As SqlFieldDataType, _ + ByRef RelationalOperator As SqlRelationalOperators, _ + ByRef FilterValue As Variant, _ + ByRef IgnoreValue As Variant, _ + ByRef Criteria As String, _ + Optional ByVal CriteriaConcatString As String = SqlOrConcatString) As Boolean Dim itm As Variant Dim ItmCriteria As String + Dim arrFilterValue() As Variant + If Not IsArray(FilterValue) Then Exit Function End If @@ -910,11 +1136,11 @@ Private Function TryBuildArrayCriteria(ByRef FieldName As String, ByVal FieldDat For Each itm In FilterValue ItmCriteria = BuildCriteria(FieldName, FieldDataType, RelationalOperator, itm, , IgnoreValue, False) If Len(ItmCriteria) > 0 Then - Criteria = Criteria & SqlOrConcatString & ItmCriteria + Criteria = Criteria & CriteriaConcatString & ItmCriteria End If Next If Len(Criteria) > 0 Then - Criteria = Mid(Criteria, Len(SqlOrConcatString) + 1) ' 1. Or wegschneiden + Criteria = Mid(Criteria, Len(CriteriaConcatString) + 1) ' 1. Or wegschneiden End If TryBuildArrayCriteria = True diff --git a/access-add-in/source/modules/StringTools.bas b/access-add-in/source/modules/StringTools.bas index 2670a0a..9d87a60 100644 --- a/access-add-in/source/modules/StringTools.bas +++ b/access-add-in/source/modules/StringTools.bas @@ -20,6 +20,7 @@ Attribute VB_Description = "String-Hilfsfunktionen" ' text/StringTools.bas ' _codelib/license.bas ' _test/text/StringToolsTests.cls +' Text functions as standard module; use only to override VBA functions such as Format project-wide (calls without prefix), otherwise prefer text/StringTools.cls ' '--------------------------------------------------------------------------------------- ' @@ -278,7 +279,7 @@ End Function ' Value - String to be checked ' ' Returns: -' Long - Anzahl Zeichen von Value +' Long - Number of characters of Value ' '--------------------------------------------------------------------------------------- Public Function Length(ByVal Value As String) As Long @@ -365,7 +366,7 @@ End Function ' Function: InsertAt '--------------------------------------------------------------------------------------- ' -' Setzt die Zeichenfolge InsertValue an der Position Pos ein +' Inserts the string InsertValue at position Pos ' ' Parameters: ' Value - String diff --git a/access-add-in/source/modules/VbeAddInInstaller.cls b/access-add-in/source/modules/VbeAddInInstaller.cls index 82b9f4d..9aaec29 100644 --- a/access-add-in/source/modules/VbeAddInInstaller.cls +++ b/access-add-in/source/modules/VbeAddInInstaller.cls @@ -11,7 +11,7 @@ Option Compare Database Option Explicit Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _ - ByVal hwnd As LongPtr, _ + ByVal Hwnd As LongPtr, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ diff --git a/access-add-in/source/modules/WinApiFileInfo.cls b/access-add-in/source/modules/WinApiFileInfo.cls index 9f597fd..5ff62cc 100644 --- a/access-add-in/source/modules/WinApiFileInfo.cls +++ b/access-add-in/source/modules/WinApiFileInfo.cls @@ -22,6 +22,7 @@ Attribute VB_Exposed = False ' ' api/winapi/WinApiFileInfo.cls ' _codelib/license.bas +' Reads the version number of a file (e.g. DLL); class version of modWinAPI_FileInfo.bas ' '--------------------------------------------------------------------------------------- ' diff --git a/access-add-in/source/modules/WinApiImageTools.cls b/access-add-in/source/modules/WinApiImageTools.cls index d384c88..9f08cde 100644 --- a/access-add-in/source/modules/WinApiImageTools.cls +++ b/access-add-in/source/modules/WinApiImageTools.cls @@ -22,10 +22,11 @@ Attribute VB_Exposed = False ' ' api/winapi/WinApiImageTools.cls ' _codelib/license.bas +' Sets the window icon of an Access form from an icon file; class version of SetFormIconFromFile in modWinAPI.bas ' '--------------------------------------------------------------------------------------- ' -Option Compare Text +Option Compare Database Option Explicit Private Const WM_MSG_SETICON As Long = &H80 @@ -37,7 +38,7 @@ Private Const LR_LOADFROMFILE As Long = &H10 #If VBA7 Then Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" ( _ - ByVal hwnd As Long, _ + ByVal Hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long @@ -53,7 +54,7 @@ Private Declare PtrSafe Function LoadImage Lib "user32" Alias "LoadImageA" ( _ #Else Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _ - ByVal hwnd As Long, _ + ByVal Hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long @@ -72,7 +73,7 @@ Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" ( _ ' Sub: SetFormIconFromFile '--------------------------------------------------------------------------------------- ' -' Spezielles Icon für ein Formular einstellen +' Set a special icon for a form ' ' Parameters: ' FormRef - Reference to the Access.Form @@ -90,7 +91,7 @@ On Error Resume Next ' ... Error message would only interfere with this "unimpor ImageHandle = LoadImage(0, IconFilePath, IMAGE_ICON, _ ICONPIXELSIZE, ICONPIXELSIZE, LR_LOADFROMFILE) If ImageHandle <> 0 Then - SendMessage FormRef.hwnd, WM_MSG_SETICON, WM_PARAM_ICON_SMALL, ByVal ImageHandle + SendMessage FormRef.Hwnd, WM_MSG_SETICON, WM_PARAM_ICON_SMALL, ByVal ImageHandle End If End Sub diff --git a/access-add-in/source/modules/WinApiLayoutTools.cls b/access-add-in/source/modules/WinApiLayoutTools.cls index f93cd34..201c438 100644 --- a/access-add-in/source/modules/WinApiLayoutTools.cls +++ b/access-add-in/source/modules/WinApiLayoutTools.cls @@ -22,6 +22,7 @@ Attribute VB_Exposed = False ' ' api/winapi/WinApiLayoutTools.cls ' _codelib/license.bas +' Layout helpers: set window back color, convert twips/pixels, get scrollbar width; class version of modWinAPI_Layout.bas ' '--------------------------------------------------------------------------------------- ' @@ -47,7 +48,7 @@ Private Declare PtrSafe Function CreateSolidBrush _ Private Declare PtrSafe Function RedrawWindow _ Lib "user32" ( _ - ByVal hwnd As LongPtr, _ + ByVal Hwnd As LongPtr, _ LprcUpdate As Any, _ ByVal HrgnUpdate As Long, _ ByVal FuRedraw As Long _ @@ -56,15 +57,15 @@ Private Declare PtrSafe Function RedrawWindow _ Private Declare PtrSafe Function SetClassLong _ Lib "user32.dll" _ Alias "SetClassLongA" ( _ - ByVal hwnd As LongPtr, _ + ByVal Hwnd As LongPtr, _ ByVal nIndex As Long, _ ByVal dwNewLong As LongPtr _ ) As Long Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal Index As Long) As Long -Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr -Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As LongPtr, ByVal DC As LongPtr) As Long +Private Declare PtrSafe Function GetDC Lib "user32" (ByVal Hwnd As LongPtr) As LongPtr +Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal Hwnd As LongPtr, ByVal DC As LongPtr) As Long Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal DC As LongPtr, ByVal Index As Long) As LongPtr #Else @@ -76,7 +77,7 @@ Private Declare Function CreateSolidBrush _ Private Declare Function RedrawWindow _ Lib "user32" ( _ - ByVal hwnd As Long, _ + ByVal Hwnd As Long, _ LprcUpdate As Any, _ ByVal HrgnUpdate As Long, _ ByVal FuRedraw As Long _ @@ -85,15 +86,15 @@ Private Declare Function RedrawWindow _ Private Declare Function SetClassLong _ Lib "user32.dll" _ Alias "SetClassLongA" ( _ - ByVal hwnd As Long, _ + ByVal Hwnd As Long, _ ByVal nIndex As Long, _ ByVal dwNewLong As Long _ ) As Long Private Declare Function GetSystemMetrics Lib "user32" (ByVal Index As Long) As Long -Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long -Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal DC As Long) As Long +Private Declare Function GetDC Lib "user32" (ByVal Hwnd As Long) As Long +Private Declare Function ReleaseDC Lib "user32" (ByVal Hwnd As Long, ByVal DC As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal DC As Long, ByVal Index As Long) As Long #End If @@ -109,16 +110,16 @@ Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal DC As Long, ByVal Inde ' Color - Color number ' '--------------------------------------------------------------------------------------- -Public Sub SetBackColor(ByVal hwnd As LongPtr, ByVal Color As Long) +Public Sub SetBackColor(ByVal Hwnd As LongPtr, ByVal Color As Long) Dim NewBrush As LongPtr 'Create Brush NewBrush = CreateSolidBrush(Color) 'Assign Brush - SetClassLong hwnd, GCL_HBRBACKGROUND, NewBrush + SetClassLong Hwnd, GCL_HBRBACKGROUND, NewBrush 'Redraw window (entire window incl. background) - RedrawWindow hwnd, ByVal 0&, ByVal 0&, RDW_INVALIDATE Or RDW_ERASE + RedrawWindow Hwnd, ByVal 0&, ByVal 0&, RDW_INVALIDATE Or RDW_ERASE End Sub diff --git a/access-add-in/source/modules/WinApiShellTools.cls b/access-add-in/source/modules/WinApiShellTools.cls index f317071..35722e1 100644 --- a/access-add-in/source/modules/WinApiShellTools.cls +++ b/access-add-in/source/modules/WinApiShellTools.cls @@ -22,6 +22,8 @@ Attribute VB_Exposed = False ' ' api/winapi/WinApiShellTools.cls ' _codelib/license.bas +' _examples/api/winapi/WinApiShellTools_Example.bas +' Opens files and URLs with the associated application (ShellExecute), runs programs as administrator, opens a new mail (mailto), starts a program and waits until it ends; class version of modWinAPI.bas ' '--------------------------------------------------------------------------------------- ' @@ -67,14 +69,14 @@ Private Const WAIT_TIMEOUT As Long = &H102& #If VBA7 Then Private Declare PtrSafe Function ShellExecuteA Lib "shell32.dll" ( _ - ByVal hwnd As LongPtr, _ + ByVal Hwnd As Long, _ ByVal lOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long -Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr +Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long Private Declare PtrSafe Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" ( _ ByVal lpBuffer As String, _ @@ -96,7 +98,7 @@ Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal DwMilliseconds As Long) #Else Private Declare Function ShellExecuteA Lib "shell32.dll" ( _ - ByVal hwnd As Long, _ + ByVal Hwnd As Long, _ ByVal lOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ @@ -129,7 +131,7 @@ Private Declare Sub Sleep Lib "kernel32" (ByVal DwMilliseconds As Long) '--------------------------------------------------------------------------------------- '--------------------------------------------------------------------------------------- -' Function: ShellExecuteOpenFile +' Function: Execute '--------------------------------------------------------------------------------------- ' ' Open file with ShellExecute @@ -149,7 +151,7 @@ Public Function Execute(ByVal FilePath As String, _ Dim Ret As Long Dim Directory As String - Dim DeskWin As LongPtr + Dim DeskWin As Long If Len(FilePath) = 0 Then Execute = False @@ -246,7 +248,7 @@ End Function ' Function: LaunchAppSynchronous '--------------------------------------------------------------------------------------- ' -' Anwnedung Synchron ausführen +' Run application synchronously ' ' Parameters: ' ExecutablePathAndName - Executable file @@ -257,7 +259,7 @@ End Function ' Boolean ' ' Remarks: -' Code hält so lange an, bis die gestartete Anwendung beendet wurde. +' Code execution waits until the started application has been closed. ' '--------------------------------------------------------------------------------------- Public Function LaunchAppSynchronous(ByVal ExecutablePathAndName As String, _ diff --git a/access-add-in/source/modules/WinApiShortcutMenu.cls b/access-add-in/source/modules/WinApiShortcutMenu.cls index 007b0d2..68f1dc0 100644 --- a/access-add-in/source/modules/WinApiShortcutMenu.cls +++ b/access-add-in/source/modules/WinApiShortcutMenu.cls @@ -14,15 +14,16 @@ Attribute VB_Description = "ShortcutMenu über Win-API" ' ' ShortcutMenu via Win API ' +' Remarks: +' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +'| Adapted variant from API example by Jörg Ostendorp of AEK10 +' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +' ' Author: ' Josef Poetzl ' -' @todo Clean up code and create doc -' ' Remarks: -'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -' | Adapted variant from API example by Jörg Ostendorp of AEK10 -'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +' TODO: Clean up code and create doc ' '--------------------------------------------------------------------------------------- @@ -32,6 +33,7 @@ Attribute VB_Description = "ShortcutMenu über Win-API" ' _codelib/license.bas ' api/winapi/WinApiLayoutTools.cls ' api/winapi/WinApiWindowTools.cls +' Shortcut (context) menu for Access forms and controls built with the WinAPI: add menu items, open the menu and return the selected item ' '--------------------------------------------------------------------------------------- ' @@ -39,11 +41,11 @@ Option Compare Text Option Explicit Private Type POINTAPI - x As Long + X As Long Y As Long End Type -Private Type RECT +Private Type Rect Left As Long Top As Long Right As Long @@ -55,7 +57,7 @@ End Type Private m_Helper As LongPtr 'Auxiliary window handle Private Type APIMSG - hwnd As LongPtr + Hwnd As LongPtr Message As LongPtr wParam As Long lParam As Long @@ -71,7 +73,7 @@ Private Declare PtrSafe Function CreateWindowEx _ ByVal lpClassname As String, _ ByVal lpWindowName As String, _ ByVal dwStyle As Long, _ - ByVal x As Long, _ + ByVal X As Long, _ ByVal Y As Long, _ ByVal nWidth As Long, _ ByVal nHeight As Long, _ @@ -97,10 +99,10 @@ Private Declare PtrSafe Function TrackPopupMenu _ Lib "user32.dll" ( _ ByVal hMenu As LongPtr, _ ByVal wFlags As Long, _ - ByVal x As Long, _ + ByVal X As Long, _ ByVal Y As Long, _ ByVal nReserved As Long, _ - ByVal hwnd As LongPtr, _ + ByVal Hwnd As LongPtr, _ lprc As Any _ ) As LongPtr 'lprc As RECT @@ -114,7 +116,7 @@ Private Declare PtrSafe Function GetMessage _ Lib "user32.dll" _ Alias "GetMessageA" ( _ ByRef lpMsg As APIMSG, _ - ByVal hwnd As LongPtr, _ + ByVal Hwnd As LongPtr, _ ByVal wMsgFilterMin As Long, _ ByVal wMsgFilterMax As Long _ ) As Long @@ -130,8 +132,8 @@ Private Declare PtrSafe Function TranslateMessage _ Private Declare PtrSafe Function GetWindowRect _ Lib "user32.dll" ( _ - ByVal hwnd As LongPtr, _ - ByRef lpRect As RECT _ + ByVal Hwnd As LongPtr, _ + ByRef lpRect As Rect _ ) As LongPtr Private Declare PtrSafe Function SetMenuDefaultItem _ @@ -146,7 +148,7 @@ Private Declare PtrSafe Function SetMenuDefaultItem _ Private m_Helper As Long 'Auxiliary window handle Private Type APIMSG - hwnd As Long + Hwnd As Long Message As Long wParam As Long lParam As Long @@ -162,7 +164,7 @@ Private Declare Function CreateWindowEx _ ByVal lpClassname As String, _ ByVal lpWindowName As String, _ ByVal dwStyle As Long, _ - ByVal x As Long, _ + ByVal X As Long, _ ByVal Y As Long, _ ByVal nWidth As Long, _ ByVal nHeight As Long, _ @@ -188,10 +190,10 @@ Private Declare Function TrackPopupMenu _ Lib "user32.dll" ( _ ByVal hMenu As Long, _ ByVal wFlags As Long, _ - ByVal x As Long, _ + ByVal X As Long, _ ByVal Y As Long, _ ByVal nReserved As Long, _ - ByVal hwnd As Long, _ + ByVal Hwnd As Long, _ lprc As Any _ ) As Long 'lprc As RECT @@ -205,7 +207,7 @@ Private Declare Function GetMessage _ Lib "user32.dll" _ Alias "GetMessageA" ( _ ByRef lpMsg As APIMSG, _ - ByVal hwnd As Long, _ + ByVal Hwnd As Long, _ ByVal wMsgFilterMin As Long, _ ByVal wMsgFilterMax As Long _ ) As Long @@ -221,7 +223,7 @@ Private Declare Function TranslateMessage _ Private Declare Function GetWindowRect _ Lib "user32.dll" ( _ - ByVal hwnd As Long, _ + ByVal Hwnd As Long, _ ByRef lpRect As RECT _ ) As Long @@ -337,13 +339,13 @@ Public Property Set MenuControl(ByRef MnuCtl As Access.Control) Select Case m_Section Case 0 'Detailbereich - lngSectionHwnd = WindowTools.GetDetailSection(ParentObj.hwnd) + lngSectionHwnd = WindowTools.GetDetailSection(ParentObj.Hwnd) Case 1 'Kopf - lngSectionHwnd = WindowTools.GetHeaderSection(ParentObj.hwnd) + lngSectionHwnd = WindowTools.GetHeaderSection(ParentObj.Hwnd) Case 2 ' Fuß - lngSectionHwnd = WindowTools.GetFooterSection(ParentObj.hwnd) + lngSectionHwnd = WindowTools.GetFooterSection(ParentObj.Hwnd) Case Else - lngSectionHwnd = WindowTools.GetDetailSection(ParentObj.hwnd) + lngSectionHwnd = WindowTools.GetDetailSection(ParentObj.Hwnd) End Select Set ParentObj = Nothing @@ -385,6 +387,7 @@ End Property ' ItemText - Menu item text ' ItemType - Menu item type ' SubMenu - Number of the assigned submenu +' DefaultItem - (optional) True: menu item is the default item ' '--------------------------------------------------------------------------------------- Public Sub AddMenuItem(ByVal MenuItemNumber As Long, ByVal ItemText As String, _ @@ -409,37 +412,37 @@ End Sub ' Function: OpenMenu '--------------------------------------------------------------------------------------- ' -' Öffnet das Popup-Menü +' Opens the popup menu ' ' Parameters: ' X - desired X position ... can be omitted if Control was specified -' X - desired Y-position ... can be omitted if Control was specified +' Y - desired Y position ... can be omitted if Control was specified ' ' Returns: ' Long - Number of the selected menu item ' '--------------------------------------------------------------------------------------- -Public Function OpenMenu(Optional ByVal x As Single = 0, Optional ByVal Y As Single = 0) As Long +Public Function OpenMenu(Optional ByVal X As Single = 0, Optional ByVal Y As Single = 0) As Long #If VBA7 Then Dim MenuHwnd As LongPtr Dim TmpHwnd As LongPtr - Dim hwnd As LongPtr + Dim Hwnd As LongPtr #Else Dim MenuHwnd As Long Dim TmpHwnd As Long - Dim hwnd As Long + Dim Hwnd As Long #End If Dim Message As APIMSG - Dim RcHelper As RECT + Dim RcHelper As Rect Dim ButtonLeft As Long Dim ButtonTop As Long Dim XPos As Long Dim YPos As Long Dim ParentObj As Object - Dim AccFormRect As RECT + Dim AccFormRect As Rect 'Otherwise, nothing is displayed when ENTER is pressed: DoEvents @@ -477,12 +480,12 @@ Public Function OpenMenu(Optional ByVal x As Single = 0, Optional ByVal Y As Sin GetWindowRect m_Helper, RcHelper If m_MenuControl Is Nothing Then - GetWindowRect m_AccessForm.hwnd, AccFormRect - ButtonLeft = LayoutTools.GetPixelFromTwips(x) + AccFormRect.Left + GetWindowRect m_AccessForm.Hwnd, AccFormRect + ButtonLeft = LayoutTools.GetPixelFromTwips(X) + AccFormRect.Left ButtonTop = LayoutTools.GetPixelFromTwips(Y) + AccFormRect.Top Else '- Buttom relative to the section window - ButtonLeft = LayoutTools.GetPixelFromTwips(m_MenuControl.Left) + LayoutTools.GetPixelFromTwips(x) + ButtonLeft = LayoutTools.GetPixelFromTwips(m_MenuControl.Left) + LayoutTools.GetPixelFromTwips(X) ButtonTop = LayoutTools.GetPixelFromTwips(m_MenuControl.Top) + LayoutTools.GetPixelFromTwips(Y) End If '- calc with each other @@ -501,20 +504,20 @@ Public Function OpenMenu(Optional ByVal x As Single = 0, Optional ByVal Y As Sin End If TrackPopupMenu MenuHwnd, TPM_BOTTOMALIGN, XPos, YPos, _ - ByVal 0&, ParentObj.hwnd, ByVal 0& + ByVal 0&, ParentObj.Hwnd, ByVal 0& 'Message-Loop (Attention: for normal forms Application.hWndAccessApp, for POPUPS Form.Hwnd) If m_AccessForm.PopUp = True Then - hwnd = m_AccessForm.hwnd + Hwnd = m_AccessForm.Hwnd Else - hwnd = Application.hWndAccessApp + Hwnd = Application.hWndAccessApp End If Dim RepeatGetMessage As Boolean Do ' Security sleep in case there are problems with windows message. (WM_MOUSELEAVE] RepeatGetMessage = False - GetMessage Message, hwnd, ByVal 0&, ByVal 0& + GetMessage Message, Hwnd, ByVal 0&, ByVal 0& TranslateMessage Message DispatchMessage Message @@ -522,7 +525,7 @@ Public Function OpenMenu(Optional ByVal x As Single = 0, Optional ByVal Y As Sin If Message.Message = WM_COMMAND Then OpenMenu = Message.wParam ElseIf Message.Message = WM_MOUSELEAVE Then - ' RepeatGetMessage = True + RepeatGetMessage = True Else OpenMenu = 0 End If diff --git a/access-add-in/source/modules/WinApiTools.cls b/access-add-in/source/modules/WinApiTools.cls index 3b210ea..9988fcf 100644 --- a/access-add-in/source/modules/WinApiTools.cls +++ b/access-add-in/source/modules/WinApiTools.cls @@ -24,10 +24,11 @@ Attribute VB_Exposed = False ' _codelib/license.bas ' api/winapi/WinApiShellTools.cls ' api/winapi/WinApiImageTools.cls +' Factory for the WinAPI helper classes (Shell, Image); entry point via WinApiToolsFactory.WinAPI ' '--------------------------------------------------------------------------------------- -Option Compare Text +Option Compare Database Option Explicit Private m_Shell As WinApiShellTools diff --git a/access-add-in/source/modules/WinApiToolsFactory.bas b/access-add-in/source/modules/WinApiToolsFactory.bas index 37d8ce6..f9d7f4d 100644 --- a/access-add-in/source/modules/WinApiToolsFactory.bas +++ b/access-add-in/source/modules/WinApiToolsFactory.bas @@ -16,10 +16,11 @@ Attribute VB_Description = "Gebräuchliche WinAPI-Funktionen" ' api/winapi/WinApiToolsFactory.bas ' _codelib/license.bas ' api/winapi/WinApiTools.cls +' Provides the global property WinAPI that returns a WinApiTools instance ' '--------------------------------------------------------------------------------------- ' -Option Compare Text +Option Compare Database Option Explicit Option Private Module diff --git a/access-add-in/source/modules/WinApiWindowTools.cls b/access-add-in/source/modules/WinApiWindowTools.cls index a81ca9b..28eb3d5 100644 --- a/access-add-in/source/modules/WinApiWindowTools.cls +++ b/access-add-in/source/modules/WinApiWindowTools.cls @@ -28,6 +28,7 @@ Attribute VB_Exposed = False ' ' api/winapi/WinApiWindowTools.cls ' _codelib/license.bas +' Gets window handles of the Access MDI client, form sections (header, detail, footer) and controls; class version of modWinAPI_Handles.bas ' '--------------------------------------------------------------------------------------- ' @@ -35,12 +36,12 @@ Option Compare Text Option Explicit Private Type POINTAPI - x As Long + X As Long Y As Long End Type Private Declare PtrSafe Function ClientToScreen Lib "user32.dll" ( _ - ByVal hwnd As LongPtr, _ + ByVal Hwnd As LongPtr, _ ByRef lpPoint As POINTAPI _ ) As Long @@ -81,10 +82,10 @@ End Function ' LongPtr ' '--------------------------------------------------------------------------------------- -Public Function GetHeaderSection(ByVal hwnd As LongPtr) As LongPtr +Public Function GetHeaderSection(ByVal Hwnd As LongPtr) As LongPtr Dim h As LongPtr 'Determine first "OFormsub" child window of the form (fhwnd) - h = FindWindowEx(hwnd, 0&, "OformSub", vbNullString) + h = FindWindowEx(Hwnd, 0&, "OformSub", vbNullString) GetHeaderSection = h End Function @@ -101,11 +102,11 @@ End Function ' LongPtr ' '--------------------------------------------------------------------------------------- -Public Function GetDetailSection(ByVal hwnd As LongPtr) As LongPtr +Public Function GetDetailSection(ByVal Hwnd As LongPtr) As LongPtr Dim h As LongPtr 'Determine first "OFormsub" child window of the form (fhwnd), starting after the header area. - h = GetHeaderSection(hwnd) - h = FindWindowEx(hwnd, h, "OformSub", vbNullString) + h = GetHeaderSection(Hwnd) + h = FindWindowEx(Hwnd, h, "OformSub", vbNullString) GetDetailSection = h End Function @@ -122,11 +123,11 @@ End Function ' LongPtr ' '--------------------------------------------------------------------------------------- -Public Function GetFooterSection(ByVal hwnd As Long) As LongPtr +Public Function GetFooterSection(ByVal Hwnd As Long) As LongPtr Dim h As LongPtr 'Determine first "OFormsub" child window of the form (fhwnd), starting after the detail area. - h = GetDetailSection(hwnd) - h = FindWindowEx(hwnd, h, "OformSub", vbNullString) + h = GetDetailSection(Hwnd) + h = FindWindowEx(Hwnd, h, "OformSub", vbNullString) GetFooterSection = h End Function @@ -140,13 +141,13 @@ End Function ' FormRef - Form reference ' Hwnd - Handle of the area on which the control is located (Header, Detail, Footer) ' ClassName - Name of the window class of the control -' ControlName - Name des Controls +' ControlName - Name of the control ' ' Returns: ' LongPtr ' '--------------------------------------------------------------------------------------- -Public Function GetControl(ByRef FormRef As Access.Form, ByVal hwnd As LongPtr, _ +Public Function GetControl(ByRef FormRef As Access.Form, ByVal Hwnd As LongPtr, _ ByVal ClassName As String, ByVal ControlName As String) As LongPtr 'Exitieren mehrere Controls der gleichen Klasse auf einem Formular, z.B. TabControls, besteht das Problem, daß @@ -170,16 +171,16 @@ On Error Resume Next Do 'Erstes (h=0)/nächstes (h<>0) Control auf dem Sektionsfenster ermitteln - h = FindWindowEx(hwnd, h, ClassName, vbNullString) + h = FindWindowEx(Hwnd, h, ClassName, vbNullString) 'Bildschirmkoordinaten dieses Controls ermitteln 'dafür die Punktkoordinaten aus dem letzten Durchlauf zurücksetzen, sonst wird addiert! - pt.x = 0 + pt.X = 0 pt.Y = 0 ClientToScreen h, pt 'Objekt bei den Koordinaten ermitteln - Set obj = FormRef.accHitTest(pt.x, pt.Y) + Set obj = FormRef.accHitTest(pt.X, pt.Y) 'Wenn Objektname = Tabname Ausstieg aus der Schleife If obj.Name = ControlName Then diff --git a/access-add-in/source/modules/_AccessCodeLib_license.bas b/access-add-in/source/modules/_AccessCodeLib_license.bas index a5dab1a..31f5e7b 100644 --- a/access-add-in/source/modules/_AccessCodeLib_license.bas +++ b/access-add-in/source/modules/_AccessCodeLib_license.bas @@ -1,15 +1,14 @@ Attribute VB_Name = "_AccessCodeLib_license" '--------------------------------------------------------------------------------------- -' access-codelib.net Lizenz +' Package: _codelib._AccessCodeLib_license +'--------------------------------------------------------------------------------------- +' +' access-codelib.net license +' +' License: '--------------------------------------------------------------------------------------- -'/** -' ' access-codelib.net Lizenz -' -' -'---------------------------------------------------------------------------------------\n -' access-codelib.net Lizenz \n -'---------------------------------------------------------------------------------------\n +'--------------------------------------------------------------------------------------- ' ' Copyright (c) access-codelib.net ' All rights reserved. @@ -34,15 +33,16 @@ ' CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ' SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ' -'---------------------------------------------------------------------------------------\n -' BSD-Lizenz im Originial: http://opensource.org/licenses/bsd-license.php \n -'---------------------------------------------------------------------------------------\n +'--------------------------------------------------------------------------------------- +' BSD-Lizenz im Originial: http://opensource.org/licenses/bsd-license.php +'--------------------------------------------------------------------------------------- ' ' Beachten Sie auch die Nutzungsbedingungen von access-codelib.net: ' http://access-codelib.net/nutzungsbedingungen.html ' -' -'**/ +' +'--------------------------------------------------------------------------------------- + '--------------------------------------------------------------------------------------- ' ' _codelib/license.bas diff --git a/access-add-in/source/modules/_initApplication.bas b/access-add-in/source/modules/_initApplication.bas index 72dd547..4d15271 100644 --- a/access-add-in/source/modules/_initApplication.bas +++ b/access-add-in/source/modules/_initApplication.bas @@ -3,7 +3,7 @@ ' Package: base._initApplication '--------------------------------------------------------------------------------------- ' -' Initialising the application +' Initializing the application ' ' Author: ' Josef Poetzl @@ -15,6 +15,7 @@ ' base/_initApplication.bas ' _codelib/license.bas ' base/modApplication.bas +' Start procedure of the ApplicationHandler framework (StartApplication, e.g. called from AutoExec) and restore of default settings ' '--------------------------------------------------------------------------------------- ' diff --git a/access-add-in/source/modules/modApplication.bas b/access-add-in/source/modules/modApplication.bas index b4884a2..b3d7c09 100644 --- a/access-add-in/source/modules/modApplication.bas +++ b/access-add-in/source/modules/modApplication.bas @@ -17,6 +17,7 @@ Attribute VB_Description = "Standard-Prozeduren für die Arbeit mit ApplicationH ' _codelib/license.bas ' base/ApplicationHandler.cls ' base/_config_Application.bas +' Standard procedures for the ApplicationHandler framework: CurrentApplication instance, application name, trace and log entries, dispose on shutdown ' '--------------------------------------------------------------------------------------- ' @@ -118,6 +119,8 @@ End Sub '--------------------------------------------------------------------------------------- Public Sub DisposeCurrentApplicationHandler() + Dim CheckCnt As Long, MaxCnt As Long + On Error Resume Next If Not m_ApplicationHandler Is Nothing Then diff --git a/access-add-in/source/modules/modErrorHandler.bas b/access-add-in/source/modules/modErrorHandler.bas index 895214d..d1453e3 100644 --- a/access-add-in/source/modules/modErrorHandler.bas +++ b/access-add-in/source/modules/modErrorHandler.bas @@ -15,6 +15,7 @@ Attribute VB_Description = "Prozeduren für die Fehlerbehandlung" ' ' base/modErrorHandler.bas ' _codelib/license.bas +' Error handling procedures (HandleError): raise to caller, show in MsgBox, ignore, optionally write to a log file ' '--------------------------------------------------------------------------------------- ' @@ -88,7 +89,7 @@ Private m_ErrorHandlerLogFile As String ' Property: DefaultErrorHandlerMode '--------------------------------------------------------------------------------------- ' -' Default behaviour of error handling +' Default behavior of error handling ' '--------------------------------------------------------------------------------------- Public Property Get DefaultErrorHandlerMode() As ACLibErrorHandlerMode @@ -125,39 +126,38 @@ End Property ' Standard procedure for error handling ' ' Parameters: -' ErrNumber"> -' ErrSource"> -' ErrDescription"> -' ErrHandlerMode"> +' ErrNumber - Error number +' ErrSource - Error source (e.g. procedure name) +' ErrDescription - (optional) Error description +' ErrHandlerMode - (optional) Error handler mode (ACLibErrorHandlerMode) ' ' Returns: ' ACLibErrorResumeMode ' -' Remarks: -'Example: -' -'Private Sub ExampleProc() +' Example: +' (start code) +' Private Sub ExampleProc() ' -'On Error GoTo HandleErr +' On Error GoTo HandleErr ' -'[...] +' [...] ' -'ExitHere: -'On Error Resume Next -' Exit Sub +' ExitHere: +' On Error Resume Next +' Exit Sub ' -'HandleErr: -' Select Case HandleError(Err.Number, "ExampleProc", Err.Description) -' Case ACLibErrorResumeMode.aclibErrResume -' Resume -' Case ACLibErrorResumeMode.aclibErrResumeNext -' Resume Next -' Case Else -' Resume ExitHere -' End Select +' HandleErr: +' Select Case HandleError(Err.Number, "ExampleProc", Err.Description) +' Case ACLibErrorResumeMode.aclibErrResume +' Resume +' Case ACLibErrorResumeMode.aclibErrResumeNext +' Resume Next +' Case Else +' Resume ExitHere +' End Select ' -'End Sub -' +' End Sub +' (end) ' '--------------------------------------------------------------------------------------- Public Function HandleError(ByVal ErrNumber As Long, ByVal ErrSource As String, _