Gemeinsam zu mehr Effizienz in der Anwendungserstellung
K |
K (→Umsetzung) |
||
Zeile 18: | Zeile 18: | ||
<source> | <source> | ||
Public Function ExecuteParamSQL(ByVal SqlText As String, _ | Public Function ExecuteParamSQL(ByVal SqlText As String, _ | ||
- | ParamArray | + | ParamArray QueryParams() As Variant) As Long |
Dim qdf As DAO.QueryDef | Dim qdf As DAO.QueryDef | ||
Zeile 25: | Zeile 25: | ||
Dim i As Long | Dim i As Long | ||
- | For i = 0 To UBound( | + | For i = 0 To UBound(QueryParams) |
- | qdf.Parameters(i) = | + | qdf.Parameters(i) = QueryParams(i) |
Next | Next | ||
qdf.Execute dbFailOnError | qdf.Execute dbFailOnError |
Programmier-Konzepte |
|
Der unten angeführte Code zeigt nur ein Prinzip und stellt keine fertige Lösung dar.
Inhaltsverzeichnis |
Eine insert- bzw. Update-Anweisung soll per VBA zusammengesetzt und mit Werten aus Variablen versorgt werden.
Public Function ExecuteParamSQL(ByVal SqlText As String, _ ParamArray QueryParams() As Variant) As Long Dim qdf As DAO.QueryDef Set qdf = CurrentDb.CreateQueryDef("", SqlText) Dim i As Long For i = 0 To UBound(QueryParams) qdf.Parameters(i) = QueryParams(i) Next qdf.Execute dbFailOnError ExecuteParamSQL = qdf.RecordsAffected End Function
anzahlDS = ExecuteParamSQL("Parameters P1 text, P2 int, P3 date; " & _ "insert into Tabelle (T, Z, D) Values ([P1], [P2], [P3])", _ "abc", 123, Now())