By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,248 Members | 1,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,248 IT Pros & Developers. It's quick & easy.

having troble with my task# auto population.

P: 1
I have a access database that I have been using for years, but I lot my codes to help me change the New task for the year. when I start typing in he info it should auto populate a new year and task number like (2018-0001) but it is not work. this is the code that is there.

Expand|Select|Wrap|Line Numbers
  1. Private Sub New_Task_Click()
  2. On Error GoTo Err_New_Task_Click
  3.  
  4.     Dim curnum As Integer
  5.     Dim curyr As Integer
  6.     'DoCmd.GoToRecord , , acNewRec
  7.     Dim rcrds As Recordset
  8.     Set rcrds = CurrentDb.OpenRecordset("SELECT [Task #], Classification FROM [Tbl:Geo Task Database] ORDER BY [Task #] DESC")
  9.  
  10.     curnum = Right(rcrds![Task #], 4)
  11.     curyr = Left(rcrds![Task #], 4)
  12.     rcrds.AddNew
  13.  
  14.     If Year(Now) = curyr Then
  15.     rcrds![Task #] = Year(Now) & Format(curnum + 1, "0000")
  16.     Else
  17.     rcrds![Task #] = Year(Now) & "0001"
  18.     End If
  19.  
  20.     rcrds![Classification] = "UNCLASS"
  21.     rcrds.Update
  22.     Me.Requery
  23.     DoCmd.GoToRecord , , acFirst
  24.  
  25. Exit_New_Task_Click:
  26.     Exit Sub
  27.  
  28. Err_New_Task_Click:
  29.     MsgBox Err.Description
  30.     Resume Exit_New_Task_Click
  31.  
  32. End Sub
Feb 23 '18 #1
Share this Question
Share on Google+
1 Reply


twinnyfo
Expert Mod 2.5K+
P: 3,212
shaqfu01,

Welcome to Bytes.

To say that your code does not work is not very helpful. Exactly what is not working? Is the code generating an error? If so, what error? If not, is the code producing an unexpected result?

This information will help us to understand and troubleshoot your problem.

Thanks!
Feb 26 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.