This is an old revision of the document!
Gibt den Inhalt einer Tabelle/Abfrage/Recordsets im Textformat aus.
printRs() ist dazu gedacht, schnell die ersten X Zeilen einer Quelle (Tabelle, Abfrage, Recordset etc) als fornatierten Text auszugeben. Das ist praktisch für Debug-Zwecke, um Beispiele zu Funktionen zu dokumentieren oder um Tabelleninhalte/Resultate in ein Forum zu posten.
Wird zum Beispiel in der [VBA][Access] Klasse SQLScript verwendet
Diese Funktion verwendet die Funktion [VBA] printList()
printRs(SELECT-Statement [,limit [,returnType[, cancel[, iFormats]]]]) printRs(recordset [,limit [,returnType[, cancel[, iFormats]]]]) printRs(tabellenname [,limit [,returnType[, cancel[, iFormats]]]]) printRs(TableDef [,limit [,returnType[, cancel[, iFormats]]]]) printRs(viewname [,limit [,returnType[, cancel[, iFormats]]]]) printRs(QueryDef [,limit [,returnType[, cancel[, iFormats]]]])
Public Function printrs( _ ByVal iRs As Variant, _ Optional ByVal iLimit As Integer = 10, _ Optional ByVal iReturn As enuPrintListOutputMethode = prListConsole, _ Optional ByRef oCancel As Boolean = False, _ Optional ByRef iFormats As Variant = Null _ ) As String
Direkt im Immadiate-Window
'Resultat einer Abfrage printrs "vw_pivot_source" | w1 | <> | 1 | 2 | 4 | |----|----|---|---|---| | 1 | | 2 | | | | 2 | | | 1 | | | 3 | | | 1 | 1 | | 4 | 0 | | | | 'Erste 5 Zeilen eines Recorsets printrs currentdb.OpenRecordset("my_table"), 5 | ID | f_date | f_string | f_double | |----|---------------------|----------|-----------| | 1 | 14.03.2014 00:01:00 | abcd | 1.15 | | 2 | 23.06.2014 11:06:10 | bv | 4 | | 3 | 14.03.2014 00:03:00 | dd | 165413.58 | | 4 | 14.03.2014 00:17:00 | dsf | 0.134 | | 11 | 14.03.2014 00:10:00 | | 0.5 | 'Rückgabe als String ?printrs("my_table", 5, prsReturn) | ID | f_date | f_string | f_double | |----|---------------------|----------|-----------| | 1 | 14.03.2014 00:01:00 | abcd | 1.15 | | 2 | 23.06.2014 11:06:10 | bv | 4 | | 3 | 14.03.2014 00:03:00 | dd | 165413.58 | | 4 | 14.03.2014 00:17:00 | dsf | 0.134 | | 11 | 14.03.2014 00:10:00 | | 0.5 | 'Direktes Auswerten eines SQL-Befehls printrs "SELECT id, f_double FROM my_table ORDER BY f_double DESC", 5 | id | f_double | |----|------------| | 3 | 165413.58 | | 22 | 16546.1654 | | 25 | 8694.1 | | 12 | 156 | | 18 | 151.584 |
Attribute VB_Name = "udf_rownr" '------------------------------------------------------------------------------- 'File : udf_rownr.bas ' All rights reserved ' http://wiki.yaslaw.info/dokuwiki/doku.php/vba 'Environment : VBA 2010 + 'Version : 1.0.0 'Name : rowNr 'Author : Stefan Erb (ERS) 'History : 04.07.2018 - ERS - Creation '------------------------------------------------------------------------------- Option Explicit '/** ' * Die Funktion dient dazu, in einer Abfrage eine Zeilennummerierung durchzuführen ' * @example Design-Ansicht: ROW_NR: rownr(now; [id]) ' * @example SQL-Ansicht: rownr(now, [id]) as ROW_NR ' * @param Variant Ein fixer Wert, der als Kennung gilt, damit eine neue Zählung beginnt. Am Besten NOW() ' * @param Variant Ein Dummy, damit die Funktion für jede Zeile aufgerufen wird. zB. [ID] ' * @param Long Der Zähler kann damit auf einen bestimmten Wert gesetzt werden ' * @return Long ' */ Public Function rowNr(Optional ByVal iSeqName As Variant = Null, Optional ByRef iDummy As Variant = Null, Optional iSetTo As Variant = Null) As Long Const C_NULL = "NULL" Static seqName As Variant Static id As Long If NZ(seqName, C_NULL) <> NZ(iSeqName, C_NULL) Then id = 0 seqName = NZ(iSeqName, C_NULL) End If id = NZ(iSetTo, id + 1) rowNr = id End Function