Filter for Text with spaces - ms-access

Using Microsoft Access I want to set a filter for records which include spaces. I tried double escaping by using '""' to no avail.
I have a table like so:
ID Title
1 Green
2 Blue Yacht
3 Yellow
and a form just displaying these records. When I now set the filter:
Form.Filter = "TestTable.Title LIKE '*Yellow*'"
it works like a charm. But when trying to filter for "Blue Yacht"
Form.Filter = "TestTable.Title LIKE '*Blue Yacht*'"
I get an empty result. Filtering for just Blue works like it is supposed to. Somehow Access doesn't like the spaces in the filter. How can I filter for e.g. "Blue " or "Blue Yacht"?

That's very strange behaviour, it should work fine as is, you could try using the Chr code instead of the space:
Form.Filter = "TestTable.Title LIKE '*Blue" & Chr(32) & "Yacht*'"

I stumbled upon this old thread while searching a solution for the same problem. I found none so far. I wonder if this is a bug on Access or what.
So, this is my case, I tried both filters below. I was working to filter and populate a Datasheet subform. Filters are in Combo Box: Citrate, Paxgene, Sodium Herapin.
Dim sTType as string
...
...
1. sTType = "[Tube Type] LIKE '" & Me.txtTubeType & "*'"
2. sTType = "[Tube Type] ='" & Me.txtTubeType & "'"
...
me.Filter = sTType
When Sodium Herapin is selected and applied as filter , the filter comes up with nothing, while I've no problem with the other word filters.
Sol.: I inserted this code way up
me.txtTubeType = iif(InStr(Trim(Me.txtTubeType), "Sod") > 0, "Sodium*", me.txtTubeType)
...
...
sTType = "[Tube Type] LIKE '" & Me.txtTubeType & "'"
me.Filter = sTType
The work around is kind of crude but it worked for my situation.
Cheers!

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.

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"

format lookupset expression

In Report Builder, I have an expression using the lookupset function that pulls back either nothing, a date and description, or several dates and several descriptions. The data it is pulling is correct. I have searched this forum and MSDN. Using what I've found in both places, I have tweaked my expression to the following.
My expression:
=Join(Lookupset(Fields!ProjectName.Value,
Fields!ProjectNames.Value,
Fields!TaskBaseline0FinishDate.Value & " - " & Fields!TaskName.Value,
"DsActivitiesCompleted"))
However, when this is displayed it doesn't have a carriage return, it just puts one after another after another. Example Below:
08/05/2015 – Milestone: Kickoff meeting Complete 08/18/2015 – Milestone: PMT Test Planning Complete 08/26/2015 – Milestone: Set CCD Date 08/26/2015 – Sprint 0 Complete 09/18/2015 – Milestone: Wave 1 Complete 09/28/2015 - Milestone: Wave 2 Complete
What I want it to look like is below. If possible I would like to have bullet points in front of each line as well.
My question is how do I get it in the format above?
Thanks,
MM
You have missed the final (optional) argument of JOIN which states which character you want to use to join your string together. Changing your expression tyo use vbCrLf (the VB new line code) as follows
=Join(Lookupset(Fields!ProjectName.Value,
Fields!ProjectNames.Value,
Fields!TaskBaseline0FinishDate.Value & " - " & Fields!TaskName.Value,
"DsActivitiesCompleted"),
vbCrLf)
Gives this output
Update
Use the below to use Chr(183) as a bullet character for each new line as well
=" " + Chr(183) + " " +
Join(Lookupset(Fields!ProjectName.Value,
Fields!ProjectNames.Value,
Fields!TaskBaseline0FinishDate.Value & " - " & Fields!TaskName.Value,
"DsActivitiesCompleted"),
vbCrLf + " " + Chr(183) + " ")

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