version=3.1.0 vdate=16.08.2017 fname=udf_printrs.bas ns=%NAMESPACE% fpath=/vba/access/functions ====== [VBA][Access] printRs() ====== //Gibt den Inhalt einer Tabelle/Abfrage/Recordsets im Textformat aus.// ==Version %%version%% (%%vdate%%)== 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:classes:sqlscript]] verwendet {{%%ns%%:%%fname%%|Download %%fname%% (V-%%version%%)}} ===== Definition ===== Diese Funktion verwendet die Funktion [[vba:functions: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 ==== Parameter-Liste ==== ***iRs** (income)
Mark text as key press Das offene DAO.Recordset. Es wird als %%ByVal%% übergeben und verändert somit das Original nicht. Es kann ein Recordet, ein SELECT-Statement, Tabellenname oder Abfragename sein ***iLimit** (income)
Maximal auszugebende Zeilen. Wenn die Zahl negativ ist, wird die Anzahl Zeilen vom Ende an ausgegeben ***iReturn** <[[vba:functions:printlist#enuprintlistoutputmethode|enuPrintListOutputMethode]]> (optional income)
Art der Rückgabe: Standart ist das Direktfenster. Alternativ kann man auch als Rückgabewert der Funktion oder in den Zwieschnepseicher des PCs schreiben. Die Auswahlen lassen sich auch kombinieren ***oCancel** (Otional outgoing)
Rückgabeflag, ob der Print_Rs aus einem Grund abgebrochen wurde ***iFormats** Ein Array mit dFormaten um die Daten zu formatieren. Siehe auch format() von VBA ===== Beispiele ===== 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 | ===== Code =====