troubleshooting Question

Access Visual Basic Code to Validate Field on Current Record Equals Value of Previous Record Plus 10

Avatar of Senniger1
Senniger1 asked on
Microsoft AccessWindows 7VBA
15 Comments1 Solution310 ViewsLast Modified:
I have Access 2010 on a Windows 7 PC.

I have an Access form.  I just added a record and I'm creating a close form button.  Before the form closes I'd like to validate the NwMtrNum field on the record I just added equals the NwMtrNum field of the previous record plus 10.

I was able to originally add 10 to the previous record when I added the new record, but I can't seem to get it to see the previous record once the new record is added.  Note the "NwMtrNum" field can be overwritten and needs to be changed sometimes which is why I want to check it.  This way when it's changed I can provide further instruction.

' Go to last record and get the value of the "NwMtrNum" field
    DoCmd.RunCommand acCmdRecordsGoToLast
        intCopyNum = Me.NwMtrNum.Value
        intCopyNum = intCopyNum + 10

    Me.AllowAdditions = True
        DoCmd.GoToRecord , , acNewRec
            Me.NwMtrNum.Value = intCopyNum

Can someone provide me with the VBA code to do this?

Thanks in advance!
Join our community to see this answer!
Unlock 1 Answer and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros