Code Snippet "VBA Access"
Parametrisierte Abfrage (Query) in Access aus VBA-Code aufrufen (ADO) und in Array einlesen
Diese Lösung kommt ohne Recordset aus
'Parametrisierte Query in Access
'Statt in Recordset wird direkt in Array eingelesen
Sub testParameters()
Dim intF As Long
Dim intFields As Long
Dim intR As Long
Dim intRecords As Long
Dim objCmd As New ADODB.Command
Dim objCon As New ADODB.Connection
Dim objPrm As ADODB.Parameter
Dim strParameterName As String
Dim strQueryName As String
Dim strText As String
Dim varData As Variant
Set objCon = CurrentProject.Connection
objCmd.CommandType = adCmdText
objCmd.CommandText = "SELECT * FROM xqryparameter"
objCmd.ActiveConnection = objCon
'Hier wird der Parameter zugewiesen
objCmd.Parameters.Append objCmd.CreateParameter( _
"@KatNr", adInteger, adParamInput, , 26)
'Daten werden direkt in Array eingelesen
varData = objCmd.Execute.GetRows
intRecords = UBound(varData, 2)
intFields = UBound(varData, 1)
For intR = 0 To intRecords
strText = ""
For intF = 0 To intFields
If strText <> "" Then
strText = strText & "; " & varData(intF, intI)
Else
strText = varData(intF, intI)
End If
Next
Debug.Print strText
Next
End Sub