Solved

File value being changed upon changing another field via a form

Posted on 2014-01-04
3
326 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 84

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 50

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

737 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