Two different formats of field in report Access 2013 - ms-access

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 & "%")

Related

How to display "Multiple" if more than one parameter value is selected or display the single value selected

I have a parameter that is multi-select. When the user selects more than one value the value "Multiple" should appear. When the user only selects one value then only that value should appear. This is for a textbox in the Header of the report.
My expression is as below:
="Division: " & IIF(Parameters!Division.Count > 1, "Multiple", Parameters!Division.Value)
I think the following expression will overcome your issue;
="Division: " & IIF(Parameters!Division.Count > 1, “Multiple Years”, JOIN(Parameters!Year.Value, ", "))

How to change the caption of a label using DLookup from pressing a button in Microsoft Access using VBA

In Microsoft access I want to be able to change the caption of a label after pressing a certain button on my form in Microsoft Access. I have tried the VBA code as shown below but it does not work and the caption stays the same.
How do I fix this ?
The field from the table is an integer called "Sem1-Credits" and the contents of this field according to the relevant programmeID is what I want the label caption to be changed to.
For example the ProgrammeID of "AM" has the Sem1-Credits of "30" in the table
The Table is called "Programme"
The unique identifier of that table is "ProgrammeID"
The name of the button is AMButton
Forms!StudentOptionForm!S1CreditsL.Caption = DLookup("[Sem1-Credits]", "Programme", "[ProgrammeID]= '" & AMButton & "'")
Thanks
You ProgrammedID could (and should) be a Long. If so, no quotes:
Forms!StudentOptionForm!S1CreditsL.Caption = DLookup("[Sem1-Credits]", "Programme", "[ProgrammeID] = " & AMButton & "")
And bevare that DLookup will return Null for no results which Caption doesn't accept, thus wrap in Nz:
Forms!StudentOptionForm!S1CreditsL.Caption = Nz(DLookup("[Sem1-Credits]", "Programme", "[ProgrammeID] = " & AMButton & ""))

Building Selection Criteria to filter record set

I use a series of if-then statements to build a selection criteria to filter records. There are several unbounded combo boxes and now I want to add checkboxes (if they are check to the criteria.) Here is the code that I am having a problem with (doesn't error or give a result - just back record):
This Section Processes checkbox minseries for true
If chkMiniSeries = True Then 'checkbox is checked'
SelCrit = SelCrit & xAnd & MiniSeries_TV = True 'add checkbox to SelCrit'
xAnd = " And "
End If
The bold indicates where i am looking for help!
Thanks for any support
You are building a filter string, so you need to concatenate a string:
SelCrit = SelCrit & xAnd & "MiniSeries_TV = True"

How to view html character & in jsp input field?

How can i try to view html character & in my jsp textbox editDescription field and i don't want to show & .
Here is my code >>>
function Edit(click)
{
var description= tablerow.cells[5].innerHTML;
document.getElementById("editDescription").value = description;
}
When i click the Edit button on the datatable, the Edit pop up will appear and binding the value like this.
one month & half day instead of one month & half day.
now i am ok with JavaScript replace method .
{document.getElementById("editDescription").value = description.replace(/&/g, '&'); }

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.