VBA-code, um eine Schleife und update MS access-Datenbank-Spalte aus Excel

Hintergrund:
Ich habe ein excel-Arbeitsblatt, das ruft Daten aus einer MS Access-Datenbank. , Der code funktioniert einwandfrei. Es ruft Datensätze auf, die "Kommentare" - Feld als leer. Benutzer aktualisieren Sie das Feld "Kommentare" in Excel, und klicken Sie auf eine Schaltfläche.

Die Fragen: Sobald der button geklickt wird, wird der VBA-code muss in einer Schleife durch alle Datensätze abgerufen, die in meiner excel-Tabelle und die Datensätze, die markiert sind, "erledigt" in excel aktualisieren müssen den gleichen Kommentar in die "Bemerkungen-Feld" in meiner Datenbank.

Ich habe mir bei diesem Artikel und Gord Thompson geschrieben einige code, der funktionieren könnte für meine situation, außer dass ich weiß nicht, wie Schneider, der code funktioniert bei mir 🙁
Link--
VBA-code zum aktualisieren /neuen Datensatz anlegen von Excel zu Access

**Momentaufnahme der Struktur meiner Datenbank und excel in diesem ** link

excel:
VBA-code, um eine Schleife und update MS access-Datenbank-Spalte aus Excel

Datenbank:
VBA-code, um eine Schleife und update MS access-Datenbank-Spalte aus Excel

Wird dieser code funktioniert

Sub Update()
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Dim xComments As String
Dim xType As String
Dim xIBES_Ticker As String
Dim xEditor As String
Dim xPRD_Year As String
Dim xPRD_Month As String
Dim xEvent_Date As String
Dim xReporting As String
Dim xNotes As String

' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=C:\Database1.mdb;"

' open a recordset
Set rs = New ADODB.Recordset
rs.Open "tablename", cn, adOpenKeyset, adLockOptimistic, adCmdTable

Range("A2").Activate  ' row 1 contains column headings
Do While Not IsEmpty(ActiveCell)

'filter all columns and update all records back instead of looking for those marked with "complete"
'guessing this will be easier to do
rs.Filter = "Type='" & xType & "' AND IBES_Ticker='" & xIBES_Ticker & "' AND Editor='" & xEditor & "' AND PRD_Year='" & xPRD_Year & "' AND PRD_Month='" & xPRD_Month & "' AND Event_Date='" & xEvent_Date & "' AND Reporting='" & xReporting & "' AND Notes='" & xNotes & "' AND Comments='" & xComments & "' "
If rs.EOF Then
Debug.Print "No existing records found..."
rs.Filter = ""
Else
Debug.Print "Existing records found..."
End If

rs("Type").Value = xType
rs("IBES_Ticker").Value = xIBES_Ticker
rs("Editor").Value = xEditor
rs("PRD_Year").Value = xPRD_Year
rs("PRD_Month").Value = xPRD_Month
rs("Event_Date").Value = xEvent_Date
rs("Reporting").Value = xReporting
rs("Notes").Value = xNotes
rs("Comments").Value = xComments

rs.Update
Debug.Print "...record update complete."

ActiveCell.Offset(1, 0).Activate  ' next cell down
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
  • Dein link kam nicht durch...
  • Entschuldigung. nur bearbeitet meine post und fügte hinzu, es es. danke für die schnelle wiederherstellen!
InformationsquelleAutor marv | 2014-03-14
Schreibe einen Kommentar