Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

datenfeld mit vba in tabelle speichern

Empfohlene Antworten

Veröffentlicht

hab mal ein problem,

ich möchte aus ein access formular nur ein bestimmtes feld in eine tabelle speichern und dann gleich prüfen ob der eintrag schon vorhanden ist, dies möchte ich in vba realisieren.

bitte um eure hilfe, wenn möglich mit vba code

Ich würde zuerst prüfen, ob der Eintrag vorhanden ist und dann diesen speichern... aber na ja, wie Du willst.


Dim rst as DAO.Recordset

Dim db as DAO.Database


Set db = CurrentDb

Set rst = db.OpenRecordset ("Meine Tabelle", dbOpenDynaset)


rst.AddNew

rst![Meine Tabellenspalte] = MeinTextfeld.Value

rst.Update


If Not rst.EOF Then

  rst.MoveFirst

End if


Do While Not rst.EOF 

  If rst![Meine Tabellenspalte] = MeinTextfeld.Value Then

     MsgBox "Das Dingen ist schon vorhanden!"

     Exit Do

  End if

  rst.MoveNext

Loop


db.Close

rst.Close

Set rst = Nothing

Set db = Nothing

Gruß

JayN

hast dosch recht, wäre das der gleiche code nur mit dem if weiter oben oder wird der code dann ganz ander??

gruß nostradamos

Ich würde es dann so gestalten:


Dim rst as DAO.Recordset

Dim db as DAO.Database

Dim prüfzahl as Integer


Set db = CurrentDb

Set rst = db.OpenRecordset ("Meine Tabelle", dbOpenDynaset)


prüfzahl = 0




If Not rst.EOF Then

  rst.MoveFirst

End if


Do While Not rst.EOF 

  If rst![Meine Tabellenspalte] = MeinTextfeld.Value Then

     prüfzahl = 1

     Exit Do

  End if

  rst.MoveNext

Loop


If prüfzahl = 0 Then

  rst.AddNew

  rst![Meine Tabellenspalte] = MeinTextfeld.Value

  rst.Update

End if


db.Close

rst.Close

Set rst = Nothing

Set db = Nothing


Gruß

JayN

ok, habs gerade in die tat umgesetzt mit guten hoffnungen, hat aber nicht so geklappt.

der kompiler meckert mit der fehlermeldung "Benutzerdefinierter Typ nicht definiert" und zeigt auf die zeile mit "Dim rst As DAO.Recordset" .

wie kann man das problem lösen??

gruß nostradamos

Du müstest im Menü "Extras" unter "Verweise" die DAO-Bibliothek einbinden.

Gruß

JayN

:D danke, dies funktioniert wunderbar

gruß nostradamos:p

Originally posted by Nostradamos

ich möchte aus ein access formular nur ein bestimmtes feld in eine tabelle speichern und dann gleich prüfen ob der eintrag schon vorhanden ist, dies möchte ich in vba realisieren.

1.) Variante für gebundenes Formular (Spalte sei numerisch):

_________________________________________________

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim temp

temp = DLookup("Spalte", "Tabelle", "Spalte=" & Me!Formfeld.Value)

If temp <> "" Then

Cancel = True

End If

End Sub

__________________________________________________

2.) Variante für ungebundenes Formular (Spalte sei ebenfalls numerisch):

__________________________________________________

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim temp

temp = DLookup("Spalte", "Tabelle", "Spalte=" & Me!Formfeld.Value)

If temp = "" Then

DoCmd.RunSQL "Insert into Tabelle(Spalte) values (" & Me!Formfeld.Value & ")"

End If

End Sub

__________________________________________________

Finde ich schön kurz und prägnant.

hth

Reinhold

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.