Please Help

JEPOOK

New Member
Joined
Sep 22, 2003
Messages
1
I am trying to get a number that will start at (2 digit month, 2 digit year (not visible) and 3 digit sequence number) that will automatically reset to 001 when the month changes. The number needs reference a table and go off the last number used. I have not been having any luck with it :oops: any suggestions?


Private Sub cmd1_Click()
Set localConnection = CurrentDb()
Set rJN = localConnection.OpenRecordset("TEST")
rJN.MoveLast

Dim cMonth As Integer
Dim cYear As Integer
Dim vYear As Integer
Dim vMonth As Integer
Dim vNum As Integer

vYear = Int(Val(Left$(rJN![Test], 2)))
vMonth = Int(Val(Mid$(rJN![Test], 2)))
vNum = Int(Val(Right$(rJN![Test], 3)))
cYear = Year(Now)
cMonth = Month(Now)

If vMonth = cMonth Then
rJN = rJN + 1
Else
rJN = "001"
End If

End Sub


:rolleyes: Thanks
Code:
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You could keep your Year/Month/Serial Number in seperate columns with a joint index set to unique. Then you can use Dmax to find the highest serial number for a given Year/Month combination. something like this.
Code:
Dim intMonth As Integer
Dim intYear As Integer
intMonth = 11
intYear = 2003

Me.lngSer = Nz(DMax("[lngSerial]", "tbleSerial", "[lngYear] = " & intYear & " and [lngMonth] = " & intMonth)) + 1

End Sub

using the NZ() function will let you roll the month over ok.
HTH

Peter
 
Upvote 0

Forum statistics

Threads
1,221,564
Messages
6,160,513
Members
451,655
Latest member
rugubara

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top