Leading Zeros for Variable Length Field - ms-access

I have a form that asks the user to enter some information into text boxes, then some VBA code that manipulates those values and enters them into a table.
One of these text boxes asks for a numeric serial number. This serial number value could be four or five digits in length, and it may contain one or more leading zero(s). e.g. 0001 or 00758 or 0463.
Once the VBA code enters this value into the table, it loops through it, increments it, and makes another entry. This repeats until all the serial numbers are added to the table. I have the serial number value taken from the text box declared as a string in my code, but it still drops my leading zeros.

I've had similar problems, using CStr() to force a string fixed it for me. So, something like: sMyString = CStr(vUserValue) instead of sMyString = vUserValue.
Also, you might be dropping the zeros when you increment the number. You can re-add them with something like: sMyString = String(5-len(sMyString),"0") & sMyString where 5 is the original number of digits.
sMyString = String(5-len(sMyString),"0") & sMyString

Related

How do I use function field's 'glidefunction:concat' correctly in servicenow?

I have created a new field in servicenow called QI (u_qi). I want to populate this field with three other fields in other words concatenate them.
My problem is, that the field is not showing up correctly. Instead of getting names, I get random chains of numbers and letters.
Here is the configuration:
And here is what I mean by random numbers and letter:
The only field showing up correctly is the number field.
Those aren't random numbers. The number field returns the CHGxxxxxx number and the other long strings are sys_id values that reference users. You need to call getDisplayValue to get a meaningful value:
glidefunction:concat(number,',',requested_by.getDisplayValue(),',',assigned_to.getDisplayValue())

Combining DMax with Dlookup to find value from last row created

I have an access database that tracks reports numbered in this way:
NNN-[two digit site code]-YY0000
The “0000” is a sequential number assigned as the reports are issued.
Examples are: NNN-SD-180001, NNN-MA-180002.
tbl_NNN stores the records.
NNN_ID is the column that stores the report numbers.
The report numbers are manually assigned, so we must keep track of the last assigned number to prevent “duplicating” the sequential 0000 number. Since users do not have visibility to the entire table of assigned numbers, they do not know which is the last number assigned. To assist them, their dashboard/form has a label that displays the last number issued. The problem we have is that the label only shows numbers that include the SD site code, MA numbers are not displayed.
My solution was to add a column named “Date_Created”, which adds a =Now() time stamp whenever a new row/number is created in the table. With the timestamp, I then intended to use Dmax to display the report number that corresponds to the last row created, regardless of the report number.
I know what I need is a combination of DLookup and Dmax, but what I came up with displays
"#Error"
in the label.
=DLookUp("NNN_ID","tbl_NNN","[Date_Created]=" & DMax("[Date_Created]","tbl_NNN"))
Am I writing this correctly?
You are close, but you must use single quotes (or unreadable expanded double quotes) for the embedded DMax:
=DLookUp("NNN_ID","tbl_NNN","[Date_Created] = DMax('[Date_Created]','tbl_NNN')")

Mysql datatype for money

i was trying to create a money related app in which users can choose their currency. Mysql datatype i tried is decimal(19,4). Now the problem is few currencies need three precisions and some need two
Eg:
oman rial needs three precisions. ie 1000 baisa = 1 omani rial. Hence my customers may enter 6.783 omani rial.
Where as my US customers will need only 2 precisions as 100 cents = 1 dollar and they may enter 5.50.
When i insert these two entries to my database using decimal(19,4), it is saved as 6.7830 and 5.5000 respectively.
Now the real pain is when i need to display their entrys as i dont want to display that extra 0 in omani rial entry and that 00 in US dollar. I also tried float but last digit gets rounded off at times.
Is there any mysql data type in which i can save exact entry as it is without any rounding off or extra zeros? If there is no such entry, how can i make it ppssible?
You can use VARCHAR to store exact representations, but I don't recommend that because it takes more bytes to store a number as a string. And any arithmetic you do on the value will convert it to a number anyway.
I recommend you use DECIMAL(19,4), and then format the value in application code, to display it with the appropriate digits. Every programming language has some function like printf() that allows you to control the output formatting, regardless of the value stored.

Allow users to input dashes to numeric field but then automatically delete dashes

I have a numeric field that I'm having some problems with. Users will be inputting a 6 digit number formatted as ##-####, but since it's a numeric field, they can't enter the dash. (unless there's a blindingly obvious solution I missed, which is entirely possible). I have it formatted to present with the dash, and I didn't think it would be a huge deal for users to just not input the dash, but my testers tell me it's very off putting to be reading a number with a dash and then not enter in a dash. I tried using an input mask, but I don't like how when you enter the control it doesn't automatically start at the beginning of the field.
Is there a way to allow the user to enter dashes into the control, and then in the before update event, it deletes all the dashes? I have a bunch of data validation for what ranges of numbers are acceptable, so I don't think I can convert it to a string field.
You will need a combination of InputMask, Format, and code-behind as shown here for entering a time:
Entering 24-hour time with input mask and full validation
Entering ISO formatted date with input mask and full validation
You should be able to modify the examples to fit your need.

access 2003 text display leading zero

We are currently using Access 2003. I have a vehicle maintenance log which has a text field for vehicle numbers. The field needs to be text as it will have a R in it when a vehicle is retired. They would like to have the field be a four digit number with leading zero's. So vehicle 22 would be displayed in the table and reports as 0022 and when retired it would be R0022. I have tried to change the format of the field to "0000" and "0000"# but neither of these will display the leading zero's.
Do you really want you users to manually edit that field?
I don't like solutions like this, because it's error-prone (unless you check a lot of things to make sure that no one enters invalid data) and feels unelegant to your users.
I would just save the following in the table:
the vehicle number in a numeric field (22, not 0022)
a boolean field which indicates if the vehicle is retired
This is much easier for your users to work with:
they can just enter new vehicle numbers without having to think about leading zeros
to retire a vehicle, they just need to set a checkbox, instead of putting the right letter in front of the vehicle number
Plus, showing the desired number R0022 now becomes just a matter of displaying/formatting the data from the table:
Public Function GetDisplayNo(VehicleNo As Integer, IsRetired As Boolean) As String
GetDisplayNo = IIf(IsRetired, "R", "") & Right("0000" & VehicleNo, 4)
End Function
You can use this function like this:
GetDisplayNo(22, True) returns R0022
GetDisplayNo(22, False) returns 0022
And if you need to display a list of vehicle numbers in a report or a continuous form, you can directly use this function in the underlying query:
SELECT
Vehicles.VehicleNo,
Vehicles.IsRetired,
GetDisplayNo([VehicleNo],[IsRetired]) AS DisplayNumber
FROM Vehicles;