Auto Number Format - ms-access

I currently have an auto number field populated in the format "\E00000".
After some thought I would like to change the auto number to the date that it is made (today's date) and then an incremented value after that, because there may be multiple records being made a day.
Example - E11072018-01 or - E11/07/2018-01
If this is possible to be created as an auto number please let me know.

You can use this fancy expression to obtain the next "number":
= Format(Date(), "\Nddmmyyyy\-") & Format(Nx(DMax("Val(Right([NumberField], 2))", "[SomeTable]", "[NumberField] Like Format(Date(), '\Nddmmyyyy\-??'"), 0), "00")
Of course, replace field and table names with those of yours.
To set value in BeforeInsert event:
Me!NumberField.Value = Format(Date(), "\Nddmmyyyy\-") & Format(Nx(DMax("Val(Right([NumberField], 2))", "[SomeTable]", "[NumberField] Like Format(Date(), '\Nddmmyyyy\-??'"), 0), "00")

Related

SSRS - show field in expression based on where clause?

I have a data table that looks like the below. This shows the top 3 subcallcategories based on the amount of calls. The "order" column is a row number that shows which order the subcallcategory was in based on the calls.
I am trying to write some DAX in SSRS which displays the following
Anxiety was the most common counselling call, followed by Work Related
Stress and Bereavement
I have written the below code however it doesn't seem to be picking up the last 2 categories? Anyone have any ideas what I am doing wrong?
=IIf(Fields!Order.Value = "1" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "") &
" was the most common counselling call, followed by " &
IIf(Fields!Order.Value = "2" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "") &
" and " & IIf(Fields!Order.Value = "3" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "")
Below is my current output
As Alan mentioned, your expression is just looking at a single row of data.
You would need to put this expression in a table with Grouping by Category.
Then you would look for the ones in your ORDER and use that Sub Cat value. I use MAX and NULL to get matching values like
=MAX(IIf(Fields!Order.Value = 1, Fields!SubCallCategory.Value, NOTHING)) &
" was the most common " & Fields!Category.Value & " call, followed by " &
MAX(IIf(Fields!Order.Value = 2, Fields!SubCallCategory.Value, NOTHING)) &
" and " & MAX(IIf(Fields!Order.Value = 3, Fields!SubCallCategory.Value, NOTHING))
The MAX will get the SubCat value over NOTHING (SSRS for NULL) for the ones in the right ORDER.
This would give one line for Counselling and one for Legal.
You could also add the totals in with
MAX(IIf(Fields!Order.Value = 1, Fields!Calls.Value, 0))
I assume your ORDER field is an INTEGER and doesn't need the quotes.

Access Textbox Custom Number Format

I am from Bangladesh and in Bangladesh comma (,) is used as thousand separator. We use comma after 3 digit, 5 digit, 7 digit from right to left like 9,999, 99,999, 9,99,999,99,99,999,9,99,99,999 & 99,99,99,999. I was trying to accomplish this format by textbox format property. When I use #,##0 as format then it only format till 5 digit. When number is 6 digit or higher then it only shows one comma like 456,456 while expected is 4,56,456. I have tried to use #,##,##,##0 but it automatically goes to #,##0. So, how can I format the text box to get my desired result as below?
You can't. You'll have to run a custom format like this:
TextValue = Format(Fix(Value), Left("##\,##\,##\,##\,##\,##\,", -Int(-(Len(Abs(Fix(Value))) - 2) \ 2) * 4) & "##0")
Note, the negative values will be formatted correctly as well while decimals will be cut off.
If you have decimals, append these:
TextValue = Format(Fix(Value), Left("##\,##\,##\,##\,##\,##\,", -Int(-(Len(Abs(Fix(Value))) - 2) \ 2) * 4) & "##0") & LTrim(Str(Abs(CCur(Value)-Fix(Value))))
As used as ControlSource (read-only) in a form or a report:
=Format(Fix([Amount]),Left("##\,##\,##\,##\,##\,##\,",-Int(-(Len(Abs(Fix([Amount])))-2)\2)*4) & "##0")
Addendum:
To cover any situation with values:
Larger than 1, with or without decimals
Smaller than 1, a positive decimal value
Zero
Larger than -1, a negative decimal value
Smaller than -1, with or without decimals
an extended expression is needed:
TextValue = Format(Value, ";-") & _
Format(Abs(Fix(Value)), Left("##\,##\,##\,##\,##\,##\,", -Int(-(Len(CStr(Abs(Fix(Value)))) - 2) \ 2) * 4) & "##0") & _
IIf(Value - Fix(Value), LTrim(Str(Abs(Value - Fix(Value)))), "")
First part controls the sign
Second part controls the integer value
Third part controls decimals
This will output correctly for any value within the entire range of Currency.

Sum values in ssrs with excluding one field

I have a report and need to Sum values from Input_Type (they are Actuals, Adjustment, Estimate, Forecast and Budget, but I need to exclude Budget).
If I use this condition, I get an error.
=SUM(IIF(Fields!INPUT_TYPE.Value = "Actuals" + Fields!INPUT_TYPE.Value = "Adjustment" + Fields!INPUT_TYPE.Value = "Estimate" + Fields!INPUT_TYPE.Value = "Forecast",Fields!VALUE.Value, 0), "GlobalReport")
Could you please help me?
Try the reverse of what you're attempting to write.
=SUM(IIF(Fields!INPUT_TYPE.Value = "Budget", 0, Fields!VALUE.Value), "GlobalReport")

Two different formats of field in report Access 2013

I'm trying to find a way to do the following:
I want to have two different formats for a certain text box. To do so, I've done the following: User types one or two digits in a form text box(who's input and format are both "#,0;0;_") and has "yes/no" box on the right of that number field which asks if it's "kg per bag"(so by default it's the other measurement unit which is Percentages), then an OnLoad event is fired when viewing the report for that form, which checks if the yes/no value is yes or no. If "yes" then the format is set to "#.0 & " kg/bag"", if no it's set to "#.0 & " %"".
I will have to additionally divide by 100 when percentages are the ones picked, but first I want the whole thing to work... Which I still can't do!
Sadly, I'm nowhere near getting it to work... Here is my current macro on the onload event of the report, which is marked as not valid expression:
Link to the image on Imgur
Or here is the MacroBuilder Code:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<UserInterfaceMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><UserInterfaceMacro For="Report" Event="OnLoad"><Statements><ConditionalBlock><If><Condition>[yn]=False</Condition><Statements><Action Name="SetValue"><Argument Name="Item">[Text0].[Format]</Argument><Argument Name="Expression">#,0 & " kg/bag"</Argument></Action></Statements></If><Else><Statements><Action Name="SetValue"><Argument Name="Item">[Text0].[Format]</Argument><Argument Name="Expression">#,0 & " %"</Argument></Action></Statements></Else></ConditionalBlock></Statements></UserInterfaceMacro></UserInterfaceMacros>
Which is displayed as:
If [yn]=False Then
SetValue
Item = [text0].[format]
Expression = #,0 & " kg/bag"
Else
SetValue
Item = [text0].[format]
Expression = #,0 & " %"
End if
Can anyone give me a hint on where to go with this? Thank you!!
P.S. Comma is my decimal separator in regional settings!
You don't really need to change format only concatenate the numeric value with unit (kg/bag or %).
Using VBA, try the following code in the OnLoad event (I am assuming the recordsource field behind the text0 control is called the same -text0):
If Forms!yourformname![yn] = False Then
Reports!yourreportname!text0 = Me.text0 & " kg/bag"
Else
Reports!yourreportname!text0 = (Me.text0)/100 & "%"
' ALTERNATIVELY: Reports!yourreportname!text0.Format = "percent"
End If
Alternatively in the OnLoad event, use an embedded macro or call an external macro with the following one action (if/then changed into the IIF function):
SetValue
Item: text0
Expression: =IIF(Forms!yourformname![yn] = False, text0 & " kg/bag", text0/100 & "%")

Allow user to separate dates with period in MS Access

I am working with an Access database where I have a form that contains several date entry fields. I have a new user that is used to using a period as a delimiter for dates so instead of "6/22/11" or "6-22-11", they enter "6.22.11". I would like to continue to allow this type of entry, but Access converts "6.22.11" to a time instead of a date. I have tried setting the format on the text box to "Short Date" with no help. I have also tried adding code to the "Lost Focus" event but that is to late since Access has already done the conversion. The "Before Update" event fires before the conversion but will not allow me to change the text in the textbox. Any ideas on how I can allow all three forms of date entry?
your above example
Private Sub Texto0_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "." Then
KeyAscii = Asc("/")
End If
End Sub
works for me.
Another aproximation is play with the BeforeUpdate and AfterUpdate events.
In BeforeUpdate you cannot modify de content of the control, but you can set a flag (a variable defined at module/form level) in the AfterUpdate event and change the content: it will trigger again the BeforeUpdate, but in this case, because is flagged you sould ignore it and unflag.
http://office.microsoft.com/en-us/access-help/control-data-entry-formats-with-input-masks-HA010096452.aspx
Input Mask.
I wrote the following function for a user who was used to entering 6 and 8 digit dates in input masks by just typing a string of numbers with no delimiter. You should be able to modify it for your purposes:
'---------------------------------------------------------------------------
' Purpose : Enables entry of 8-digit dates with no delimiters: 12312008
' Usage : Set OnChange: =DateCtlChange([Form].[ActiveControl])
' 8/ 6/09 : Allow entry of 6-digit dates with no delimiters
' (year 2019 and 2020 must still be entered as 8-digit dates)
'---------------------------------------------------------------------------
Function DateCtlChange(DateCtl As TextBox)
Dim s As String, NewS As String
On Error GoTo Err_DateCtlChange
s = DateCtl.Text
Select Case Len(s)
Case 6
If s Like "######" Then
If Right(s, 2) <> "19" And Right(s, 2) <> "20" Then
NewS = Left(s, 2) & "/" & Mid(s, 3, 2) & "/" & Mid(s, 5, 2)
End If
End If
Case 8
If s Like "########" Then
NewS = Left(s, 2) & "/" & Mid(s, 3, 2) & "/" & Mid(s, 5, 4)
End If
End Select
If IsDate(NewS) Then
DateCtl.Text = NewS
DateCtl.SelStart = Len(DateCtl.Text)
End If
Exit_DateCtlChange:
Exit Function
Err_DateCtlChange:
Select Case Err.Number
'Error 2101 is raised when we try to set the text to a date
' that fails the date control's validation
Case 2101 'The setting you entered isn't valid for this property.
'Log error but don't show user
Case Else
'Add your custom error logging here
End Select
Resume Exit_DateCtlChange
End Function
Access uses the system date and time format to determine how to translate a value. Another option - that would affect every program on this user's computer - is this: http://office.microsoft.com/en-us/access-help/change-the-default-date-time-number-or-measurement-format-HA010351415.aspx?CTT=1#BM2
Alternatively you can use spaces instead of slashes in dates in Access. Thus the user can use the left hand on the space bar and use the right hand on the numeric keyboard. I feel this is much easier to use than either the slash or the hyphen.