DAO Recordset Edit command not running

oldcitycat

Board Regular
Joined
Sep 23, 2011
Messages
71
First and foremost this is my first attempt at using a recordset!
With that in mind I did my researched and thought I understood but this issue has me stumped.

The code works up to rs.edit statement
I have verified that the If statement is true by stepping through the code,
When it gets to the rs.edit it jumps to end if, No error messages
The one thing I unsure of is if the recordset is locked by default when opened.

Code:
Sub CodeTesting()Dim db As Database
Dim rs As DAO.Recordset
Dim strNotes As String
Dim strOrderNumber As String

    Set db = CurrentDb
    Set rs = db.OpenRecordset("DailyMopOrds")

    rs.MoveFirst
    Do Until rs.EOF
    
    If rs!Notes <> " " Then
        strNotes = rs!Notes
        strOrderNumber = rs!OrderNumber
        rs.MoveNext
    End If
    
    If rs!Notes = "" And rs!OrderNumber = strOrderNumber Then
        rs.Edit
        rs!Notes = strNotes
        rs.Update
End If
        rs.MoveNext
Loop
End Sub

Sample Data
OrderNumberOrderDate PONumberNotes
M50143652/27/2017 AF373C/MAR17****MARCH ORDER SHIP AFTER THE 1st***
M50143652/27/2017 AF373C/MAR17
M50143662/27/2017AF0C70/MAR17***MARCH ORDER SHIP AFTER THE 1st**
M50143672/27/2017AF1510/APR17****APRIL ORDER PLEASE SHIP AFTER 4/1****
M50143672/27/2017AF1510/APR17

<tbody>
</tbody>

Thank you in advance for any and all suggestions
OldCitCat
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
you should test for 0 records else rs.MoveFirst will generate an error if BOF and EOF are true (zero records).
Is it possible that Notes contains one space? " " Or are you trying to test for an empty string?
What is the value of rs.Notes since you say the test is passing?
Which If test are you referring to? You're testing for 2 different values in those tests; " " and ""
Step through the code and in the Immediate window, test each rs.field or variable after the line has been processed. Such as ?rs.Notes, then hit Enter.
 
Upvote 0
Do this with SQL ;)
 
Last edited:
Upvote 0
Note: or better yet, don't do it at all. You should not have duplicated notes saved in you database as this introduces the danger of data anomalies. Why are your notes being stored this way?

Also, btw, note text is notoriously bad data to work with (you get newlines, tabs, strange characters of all kinds, even invisible characters copied in from web pages). So unless your notes are machine generated, this could be ugly someday.

Also btw your code works fine for me - at least, no errors and the updates succeed. ;)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,709
Messages
6,161,442
Members
451,705
Latest member
Priti_190

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top