{"id":2076,"date":"2013-11-11T23:16:21","date_gmt":"2013-11-11T21:16:21","guid":{"rendered":"http:\/\/www.ramses.de\/?p=2076"},"modified":"2013-11-11T23:16:21","modified_gmt":"2013-11-11T21:16:21","slug":"faq-access-neue-felder-per-vba-anlegen","status":"publish","type":"post","link":"https:\/\/www.ramses.de\/?p=2076","title":{"rendered":"FAQ Access &#8211; Neue Felder per VBA anlegen"},"content":{"rendered":"<div>\n<h1>Access VBA &#8211; Neue Felder per VBA anlegen<\/h1>\n<\/div>\n<div>\n<h2><strong>Problem <\/strong><\/h2>\n<p>Sie m\u00f6chten per VBA ein Feld neu anlegen, d.h. Sie wollen bzw. k\u00f6nnen nicht in die Entwurfsansicht einer Tabelle gehen, da sich die Tabelle &#8222;au\u00dfer Reichweite&#8220; beim Kunden befindet?<\/p>\n<h2><strong>L\u00f6sung <\/strong><\/h2>\n<p>Nutzen Sie die CreateField Methode<\/p>\n<pre>Function NeuesFeld()<\/pre>\n<pre>On Error Resume Next<\/pre>\n<pre> 'dbBigInt Big Integer-Daten (nur ODBCDirect)<\/pre>\n<pre> 'dbBinary Bin\u00e4rdaten<\/pre>\n<pre> 'dbBoolean Boolesche Daten (True\/False)<\/pre>\n<pre> 'dbByte Byte-Daten (8-Bit)<\/pre>\n<pre> 'dbChar Zeichensatzdaten (nur ODBCDirect)<\/pre>\n<pre> 'dbCurrency W\u00e4hrungsdaten<\/pre>\n<pre> 'dbDate Datumswerte<\/pre>\n<pre> 'dbDecimal Dezimaldaten (nur ODBCDirect)<\/pre>\n<pre> 'dbDouble Flie\u00dfkommadaten mit doppelter Genauigkeit<\/pre>\n<pre> 'dbFloat Flie\u00dfkommadaten (nur ODBCDirect)<\/pre>\n<pre> 'dbGUID Guid - Daten<\/pre>\n<pre> 'dbInteger Integer-Daten<\/pre>\n<pre> 'dbLong Long Integer-Daten<\/pre>\n<pre> 'dbLongBinary Bin\u00e4rdaten(Bitmap)<\/pre>\n<pre> 'dbMemo Memo-Daten (erweiterter Text)<\/pre>\n<pre> 'dbNumeric Numerische Daten (nur ODBCDirect)<\/pre>\n<pre> 'dbSingle Flie\u00dfkommadaten mit einfacher Genauigkeit<\/pre>\n<pre> 'dbText Textdaten (variable L\u00e4nge)<\/pre>\n<pre> 'dbTime Daten im Zeitformat (nur ODBCDirect)<\/pre>\n<pre> 'dbTimeStamp Daten in Zeit- und Datumsformat (nur ODBCDirect)<\/pre>\n<pre> 'dbVarBinary Variable Bin\u00e4rdaten (nur ODBCDirect)<\/pre>\n<pre> Dim wsp As Workspace<\/pre>\n<pre> Dim db As Database<\/pre>\n<pre> Dim vTabelle As TableDef, fld1 As Field ' Verweis auf aktuelle Datenbank holen.<\/pre>\n<pre> Set wsp = DBEngine.Workspaces(0)<\/pre>\n<pre> Set db = wsp.OpenDatabase(DATENMDB) ' Erstellen einer neuen Tabelle mit zwei Feldern.<\/pre>\n<pre> Set vTabelle = db.TableDefs!TBAUFTRAEGE<\/pre>\n<pre> Set fld1 = vTabelle.CreateField(\"ATMITTELBINDUNG\", dbText, 255)<\/pre>\n<pre> Call SetFieldProperty(\"TBAUFTRAEGE\", \"ATMITTELBINDUNG\", \"Description\", \"TBAUFTRAEGE - ATMITTELBINDUNG\")<\/pre>\n<pre> Call SetFieldProperty(\"TBAUFTRAEGE\", \"ATMITTELBINDUNG\", \"Caption\", \"MIttelbindungsnummer\")<\/pre>\n<pre> ' Felder anf\u00fcgen.<\/pre>\n<pre> vTabelle.Fields.Append fld1<\/pre>\n<pre> MsgBox \"Die neuen Felder wurde erfolgreich angelegt\", , MSGBOXTITEL<\/pre>\n<pre> End Function<\/pre>\n<pre> Public Function SetFieldProperty(TblName, FldName, Optional PrpName, Optional PrpVal, Optional PrpType)<\/pre>\n<pre> On Error Resume Next<\/pre>\n<pre> Dim db As Database, Tbl As DAO.TableDef, Fld As DAO.Field, Prp As DAO.Property<\/pre>\n<pre> 'Aufruf der Funktion zum Setzten einer Eigenschaft : SetFieldProperty \"MeineTabelle\",\"MeinFeld\",\"Format\",\"Currency\"<\/pre>\n<pre> 'Aufruf der Funktion zum L\u00f6schen einer Eigenschaft :SetFieldProperty \"MeineTabelle\",\"Feld1\",\"Description\",\"\"<\/pre>\n<pre> Set db = CurrentDb<\/pre>\n<pre> Set Tbl = db.TableDefs(TblName)<\/pre>\n<pre> Set Fld = Tbl.Fields(FldName)<\/pre>\n<pre> On Error Resume Next<\/pre>\n<pre> If PrpVal = \"\" Then ' remove property<\/pre>\n<pre> Fld.Properties.Delete PrpName<\/pre>\n<pre> Else<\/pre>\n<pre> Fld.Properties(PrpName) = PrpVal<\/pre>\n<pre> If err.Number = 3270 Then ' property not yet defined<\/pre>\n<pre> On Error GoTo 0<\/pre>\n<pre> Set Prp = Fld.CreateProperty(PrpName, PrpType, PrpVal)<\/pre>\n<pre> Fld.Properties.Append Prp<\/pre>\n<pre> Else<\/pre>\n<pre> MsgBox err.Description<\/pre>\n<pre> End If<\/pre>\n<pre> End If<\/pre>\n<pre> End Function<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Access VBA &#8211; Neue Felder per VBA anlegen Problem Sie m\u00f6chten per VBA ein Feld neu anlegen, d.h. Sie wollen bzw. k\u00f6nnen nicht in die &#8230; <a title=\"FAQ Access &#8211; Neue Felder per VBA anlegen\" class=\"read-more\" href=\"https:\/\/www.ramses.de\/?p=2076\" aria-label=\"Mehr Informationen \u00fcber FAQ Access &#8211; Neue Felder per VBA anlegen\">Weiterlesen &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47,43],"tags":[58,82],"class_list":["post-2076","post","type-post","status-publish","format-standard","hentry","category-access","category-faq","tag-access-2010","tag-beziehungen"],"_links":{"self":[{"href":"https:\/\/www.ramses.de\/index.php?rest_route=\/wp\/v2\/posts\/2076","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ramses.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ramses.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ramses.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ramses.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2076"}],"version-history":[{"count":1,"href":"https:\/\/www.ramses.de\/index.php?rest_route=\/wp\/v2\/posts\/2076\/revisions"}],"predecessor-version":[{"id":2077,"href":"https:\/\/www.ramses.de\/index.php?rest_route=\/wp\/v2\/posts\/2076\/revisions\/2077"}],"wp:attachment":[{"href":"https:\/\/www.ramses.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ramses.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ramses.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}