Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / December 2007

Tip: Looking for answers? Try searching our database.

Previous Command No Longer Works

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pushrodengine - 20 Dec 2007 01:12 GMT
I’m using coding below to insert “0000-yy” into a textbox.
The numbering system works great except that I have lost the ability to move
back to the previous record. It must be something to do with the code.

How can I fix it?

Private Sub Form_Current()
 If Me.NewRecord Then
      Dim strWhere As String
      Dim varResult As Variant

      strWhere = "IncidentID Like """ & Format(Date, "yy") & "*"""
      varResult = DMax("IncidentID", "tblIncidentLog", strWhere)

      If IsNull(varResult) Then
          Me.IncidentID = Format(Date, "yy") & "-0001"
      Else
          Me.IncidentID = Left(varResult, 3) & _
              Format(Val(right(varResult, 4)) + 1, "0000")
      End If
   End If
End Sub
Allen Browne - 20 Dec 2007 01:55 GMT
You *never* want to assign a value to a bound control in Form_Current. It
makes no sense to alter the data in the record just because somebody visited
it. That would imply that the data would be invalid if nobody visited the
record.

In your case, you don't want to dirty the record until you know the user
intends entering something. Ideally, you want to run this at the last
possible moment before the new record is saved, to reduce the possibility
that 2 users entering data together are given the same number. Move the code
into Form_BeforeUpdate().

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> I’m using coding below to insert “0000-yy” into a textbox.
> The numbering system works great except that I have lost the ability to
[quoted text clipped - 19 lines]
>    End If
> End Sub
pushrodengine - 20 Dec 2007 03:57 GMT
Thank You for The Help!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.