Solved

File value being changed upon changing another field via a form

Posted on 2014-01-04
3
327 Views
Last Modified: 2014-01-04
I have a a field called  "FileNo"  this number is generated automatically via

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.FileNo = Year(Date) & "1" & Format(Me.InvoiceID, "00000")
End Sub.


The problem is that I have a record that was created last year as example

FileNo =  201312345677

when  a user opens the record via the form and changes one of the field values the FileNo is being recreated and saved as :

FileNo = 201412345677


ONce the FileNo is originally created I do not want it changed no matter what other changes to the record are being made subsequent to the intial creation of the FileNo.


Please help.
0
Comment
Question by:seamus9909
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39756174
Use Before_Insert instead of Before_Update.

Before_Update runs anytime a user edits a record, or adds a new record.

Before_Insert runs only when a new record is added.

Or you can check to see if the user is adding a new record in your Before_Update:
Private Sub Form_BeforeUpdate(Cancel As Integer)
  If Me.NewRecord Then
    Me.FileNo = Year(Date) & "1" & Format(Me.InvoiceID, "00000")
  End If
End Sub

Open in new window

0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39756177
You can use:

Private Sub Form_BeforeUpdate(Cancel As Integer)
  If isNull(Me.FileNo) Then
    Me.FileNo = Year(Date) & "1" & Format(Me.InvoiceID, "00000")
  End If
End Sub

/gustav
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39756239
try this


Private Sub Form_BeforeUpdate(Cancel As Integer)

if me.newrecord then

          Me.FileNo = Year(Date) & "1" & Format(Me.InvoiceID, "00000")

end if
End Sub
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question