Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

File value being changed upon changing another field via a form

Posted on 2014-01-04
3
Medium Priority
?
328 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 2000 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

722 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