Code Snippet "VBA Access"
Bericht, Abfrage oder Formular für aktuellen Datensatz öffnen
Aufruf via cmdrechnungsdruck
Ereignis "Beim Klicken": =funblngotoquery("rptrechnung";"rechnungsnr=" & [rechnungsnr])
Code
Public Function funblngotoquery(ByVal strqueryname As String, _
Optional strwherecondition As String) As Boolean
Dim obj As AccessObject
On Error GoTo Err_funblngotoquery
'Formulare
For Each obj In Application.CurrentProject.AllForms
If obj.Name = strqueryname Then
DoCmd.OpenForm strqueryname, , , strwherecondition
funblngotoquery = True
Exit Function
End If
Next obj
'Berichte
For Each obj In Application.CurrentProject.AllReports
If obj.Name = strqueryname Then
DoCmd.OpenReport strqueryname, acViewPreview, , strwherecondition
funblngotoquery = True
Exit Function
End If
Next obj
'Abfragen
For Each obj In Application.CurrentData.AllQueries
'MsgBox Application.CurrentData.AllQueries.Item(7).Type
If obj.Name = strqueryname Then
DoCmd.OpenQuery strqueryname, acNormal, acEdit
funblngotoquery = True
Exit Function
End If
Next obj
funblngotoquery = False
Exit_funblngotoquery:
Exit Function
Err_funblngotoquery:
MsgBox Err.Description & " " & Err.Number
funblngotoquery = False
Resume Exit_funblngotoquery
End Function