Results 1 to 7 of 7
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365

    Updating Recordset

    Hi Guy's, hope you are all well, this one should be a simple fix!



    I am trying to update a recordset between 2 dates with a criteria: if an email address exists, then update Send Reminder field with the email addresses

    If an email address doesn't exist looping through the records then just "N/A"

    Result: There is nothing being added to the Send Reminder Field

    Code:
    Dim rs as dao,Recordset, sDate as Date,eDate as Date, em as String
    sDate = Me.txtFrom
    eDate = Me.txtDateTo
    Set rs = CurrentDb.OpenRecordset("Select * From tblRemovals WHERE RemovalDate Between #" & sDate & "# And #" & eDate & "#")
    With rs
        rs.MoveFirst
    Do Until rs.EOF
        .Edit
    If Not IsNull(rs.Fields("Email")) Then
        em = rs.Fields("Email")
    Else
        em = "N/A"
    End If
        rs.Fields("SendReminder") = em
        rs.Update
        rs.MoveNext
    Loop
    End With
        rs.Close
    Set rs = Nothing
        Me.frmWebTimes.Requery

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    A. You should check EOF before even trying to use a recordset
    B. Walk though your code with F8 and a breakpoint. That always allows you to find silly errors.

    At first glance, I cannot see anything else wrong with your code, and that would be my approach was it mine and in the same situation.
    Perhaps move the Edit to just before you set the field.?

    You should also not be storing the same info more than once?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Thanks WGM, update or cancel update without add new or edit

    I think i just have something in the wrong sequence ??????

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Changed to this adding if not BOF and EOF

    Still comes up with update or cancel update without add new or edit

    Debugs on the bold line

    Code:
    Set rs = CurrentDb.OpenRecordset("Select * From tblRemovals WHERE RemovalDate Between #" & sDate & "# And #" & eDate & "#")
    With rs
    .Edit
    If Not (rs.BOF And rs.EOF) Then
    Do Until rs.EOF
        rs.MoveFirst
        rs.Fields("SendReminder") = rs.Fields("Email") (DEBUGS THIS LINE)
        rs.MoveNext
    Loop
    .Update
    End If
    End With
        rs.Close
    Set rs = Nothing
        Me.frmWebTimes.Requery

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Code:
    Dim rs As DAO, Recordset, sDate As Date, eDate As Date, em As String
    sDate = Me.txtFrom
    eDate = Me.txtDateTo
    Set rs = CurrentDb.OpenRecordset("Select * From tblRemovals WHERE RemovalDate Between #" & sDate & "# And #" & eDate & "#")
    With rs
        .MoveFirst
        Do Until .EOF
    
            If Not IsNull(rs.Fields("Email")) Then
                em = .Fields("Email")
            Else
                em = "N/A"
            End If
            .Edit
            .Fields("SendReminder") = em
            .Update
            .MoveNext
        Loop
    End With
    rs.Close
    Set rs = Nothing
    Me.frmWebTimes.Requery
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Perfect thank you WGM

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Dave,
    Look at the code you posted.
    It would never stop.
    You were lucky it did not run.

    You really need to understand what you are writing. Computers are not very forgiving. I can see what you mean, but a computer will just follow your instructions blindly.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Updating a RecordSet Clone
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 01-13-2018, 03:43 PM
  2. Updating Recordset with VBA Code
    By adams77 in forum Modules
    Replies: 2
    Last Post: 07-31-2015, 10:57 AM
  3. Replies: 4
    Last Post: 01-22-2015, 09:57 AM
  4. Recordset loop not updating and breaks
    By Ruegen in forum Programming
    Replies: 1
    Last Post: 02-24-2014, 05:33 PM
  5. Replies: 1
    Last Post: 04-04-2012, 05:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums