Consulting

Results 1 to 2 of 2

Thread: Solved: Find record and edit field in database

  1. #1

    Question Solved: Find record and edit field in database

    Hello everyone,

    I won't get my code to work. I get an error message saying "Update or CancelUpdate without Edit or AddNew". But i'm using Edit?! I don't get it.

    As you may see i'm trying to loop through my sheet to find a true If-statement and then search the database for the record matching Cells(lngRow, 1) and entering "1" in the Field name gstrBannedArticlesDB (string).


    [VBA]Public Sub gBanArticle()

    Dim dbDatabase As dao.Database
    Dim dbRecordSet As dao.Recordset
    Dim lngRow As Long
    Dim lngPos As Long

    Set dbDatabase = OpenDatabase(gstrImportPath1)

    lngRow = 2
    Do
    If frmMain.lstExportView.Selected(lngRow - 1) = True Then

    Set dbRecordSet = bDatabase.OpenRecordset(gstrDatabaseTable, dbOpenDynaset)
    With dbRecordSet
    .Edit
    .FindFirst ("product_id = '" & Sheets(gstrFilename).Cells(lngRow, 1) & "'")
    .Fields(gstrBannedArticlesDB) = "1" 'the error occurs here
    .Update
    End With

    dbRecordSet.Close
    Set dbRecordSet = Nothing
    End If
    lngRow = lngRow + 1
    Loop Until Sheets(gstrFilename).Cells(lngRow, 1) = ""

    dbDatabase.Close
    Set dbDatabase = Nothing

    End Sub[/VBA]


    Thanks in advance

  2. #2
    just solved it myself with

    [VBA] With dbRecordSet
    .MoveFirst

    Do While Not .EOF
    If Trim(dbRecordSet("product_id")) = Trim(Sheets(gstrFilename).Cells(lngRow, 1)) Then
    .Edit
    .Fields(gstrBannedArticlesDB) = "1"
    .Update
    Exit Do
    End If
    .MoveNext
    Loop
    End With[/VBA]

    thanks anyway

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •