REF: thread701-1454746
I am trying to create a smart number for a user. Currently they are using this system manually and have been for years. They want the "Julian" (Ordinal)date to be used in this format:Year-Julian Date-sequential number. EX: 08-185-01
This would signify that the report was created in 08 on day 185 and that was the first report for the day.
I copied the following code and all I get is a blank field. I don't even get the error message.
I never had any programming training and so I am really challenged. I even added a field called ControlNumber so that there would not be a conflict with names.
1. Where do I add the code? In the OnClick Event?
2. What else did I do wrong? I saw there were a couple of corrections after this code, but I didn't know how or where to apply them.
Here is what I copied:
Option Compare Database
Dim CurrentDate As Date
Dim LastDate As Date
Dim VisitOrder As Integer
Private Sub ControlNumber_Click()
Dim rst As DAO.Recordset
Dim JulianDate, myDate As Integer
Dim CurrentDate, LastDate, myDate1 As Date
Dim ControlNumber, JulianDate1, OutPtNbr1,
VisitOrder1 As String
OutPtNbr = "48"
VisitOrder = Format(1, "000")
On Error GoTo Err_Execute
Set rst = Me.Recordset
'set current date to today
CurrentDate = DateValue(Now())
'Retrieve JulianDate
JulianDate = Format(CurrentDate -
DateSerial(Year(CurrentDate) - 1, 12, 31), "000")
'get next days visit number order
If Me.NewRecord Then 'if this a new record then
VisitOrder = Nz(DMax(VisitOrder, "ControlNumber",
[CurrentDate NOT LastDate]), 0) + 1 'and current date
equals last date increment
Else
VisitOrder = DMax(VisitOrder, "ControlNumber",
[CurrentDate=LastDate]) +1
End If
JulianDate1 = CStr(Format(JulianDate, "000"))
VisitOrder1 = CStr(Format(VisitOrder, "000"))
ControlNumber = OutPtNbr & JulianDate1 & VisitOrder1
Me!ControlNumber = ControlNumber
Err_Execute:
'An error occurred, return blank string
ControlNumber = ""
MsgBox "An error occurred while trying to determine
the next ControlNumber to assign."
End Sub
Thanks for any help you can give.
Same Circus, Different Clowns
I am trying to create a smart number for a user. Currently they are using this system manually and have been for years. They want the "Julian" (Ordinal)date to be used in this format:Year-Julian Date-sequential number. EX: 08-185-01
This would signify that the report was created in 08 on day 185 and that was the first report for the day.
I copied the following code and all I get is a blank field. I don't even get the error message.
I never had any programming training and so I am really challenged. I even added a field called ControlNumber so that there would not be a conflict with names.
1. Where do I add the code? In the OnClick Event?
2. What else did I do wrong? I saw there were a couple of corrections after this code, but I didn't know how or where to apply them.
Here is what I copied:
Option Compare Database
Dim CurrentDate As Date
Dim LastDate As Date
Dim VisitOrder As Integer
Private Sub ControlNumber_Click()
Dim rst As DAO.Recordset
Dim JulianDate, myDate As Integer
Dim CurrentDate, LastDate, myDate1 As Date
Dim ControlNumber, JulianDate1, OutPtNbr1,
VisitOrder1 As String
OutPtNbr = "48"
VisitOrder = Format(1, "000")
On Error GoTo Err_Execute
Set rst = Me.Recordset
'set current date to today
CurrentDate = DateValue(Now())
'Retrieve JulianDate
JulianDate = Format(CurrentDate -
DateSerial(Year(CurrentDate) - 1, 12, 31), "000")
'get next days visit number order
If Me.NewRecord Then 'if this a new record then
VisitOrder = Nz(DMax(VisitOrder, "ControlNumber",
[CurrentDate NOT LastDate]), 0) + 1 'and current date
equals last date increment
Else
VisitOrder = DMax(VisitOrder, "ControlNumber",
[CurrentDate=LastDate]) +1
End If
JulianDate1 = CStr(Format(JulianDate, "000"))
VisitOrder1 = CStr(Format(VisitOrder, "000"))
ControlNumber = OutPtNbr & JulianDate1 & VisitOrder1
Me!ControlNumber = ControlNumber
Err_Execute:
'An error occurred, return blank string
ControlNumber = ""
MsgBox "An error occurred while trying to determine
the next ControlNumber to assign."
End Sub
Thanks for any help you can give.
Same Circus, Different Clowns