Access VBA: Set conditional format on duplicate text values - ms-access

my first question here but I can't seem to find an answer anywhere.
I have created a report on which colleagues can see appointments booked by users.
But my colleagues would like to have a clear view of users with the same lastname so no appointments get mixed.
Example:
Joe Smith is booked at 15 o'clock.
Jane Smith is booked at 10 o'clock.
I would like to have the lastname Smith underlined/bold so the name "pops" while checking the list.
I've found some info regarding DCount but can't seem to be able to put it to use. I thought perhaps a Match-function might also work, but I can't specify cells of the Access report.
So I hope you guys can help me further.
Thanks anyway!
EDIT:
Here is a small screenshot, the name should be highlighted when it appears more than once in the report.
AccessReport

Here is the DCount you need.
Nz(DCount("*","[table]","[LastNameField] = '" & [LastNameField] & "'"),0)>1
I made a test database real quick to verify this worked. It goes in the conditional formatting expression. Just replace the table and field names to what you are using.

Related

SSAS Dimension - genuinely repeated data in 1 column, how to deal?

I have a dimension (DimContact) which looks like this:
ContactAlternateKey ContactDOB ContactFullName ContactPostalAddress
12345 17.4.2000 Timo Ohio 17 Blah Street
12346 17.4.2000 Miki Massa 25 Other Street
12347 19.1.1999 Sven Tokio 17 Blah Street
I have another Dim which is used for Addresses based on ParcelID (that's the ID for that actual piece of land) which works as planned. This Dim is populated from free text fields inside the source system, and not as structured as our Parcel data, also, the contactpostaladdress isn't necessarily in our country, so is just there for supporting information, rather than to serve a legitimate purpose.
When I process the Dim WITHOUT the ContactPostalAddress field as an attribute, everything works to plan, however as soon as I use that field too SSAS complains about a duplicate attribute key (which is one of the addresses that has been repeated - but actually the ContactFullName is different (2 people living at the same address), so is genuinely a different record.
Can anyone suggest how to get around this please? I am confused, as surely there are duplicate ContactDOB's in there too which SSAS is happy to work around.
I am using VS2015 on SQL Server 2016 Standard Edition.
Thank you
Moments later I had a lightbulb moment - and have implemented a change in the KeyColumns area of the Properties for the ContactPostalAddress. I have ordered the "Key Columns" with ContactAlternateKey as first on the list and then ContactPostalAddress as second on the list. This forces SSAS to do a distinct(both columns) when building the table, rather than just a distinct(ContactPostalAddress). This works a treat and hopefully will help another user in the future.

Extracting words from a paragraph and then match with existing database by Ms Access

I am the beginner on the usage of MS Access.
I am going to build a program in the MS Access 2007 which can scanning some specific wordings listed in the data table from a paragraph.
For example, I want to know the occurrences of the transportation taken by the students.
(i) Therefore, I set the words "school" and "Bus" in my datatable [tableA] fields [trans].
(ii) Then, I input "I go to school by bus." in the [Input] boxes.
(iii) The result i want is that the sun of occurrences of both "school" and "Bus" can be showed in the another one textbox.
In the current situation, i just create a query [QueryA] from the [tableA] and directly use the count function in the query form. And then set the criteria as " Like [forms]![tableA]![Input] & "*" ".
However, it can just match the words in the [Input] with the final count result of the Query.
Ths a lot for providing any advice, including new direction.
I hope I understand what you're asking here, so I'll give it a stab with the information that you've provided. In your SQL window, try the following script: NOTE: You will need to change the WHERE clause to reflect your Input box(s)
SELECT Count(*) AS Expr1
FROM tableA
WHERE tableA.[trans] Like '%[Input]%;

SSRS: How to select two or more values from a long filtered multiple selection list with different search strings

Let's consider a multiple selection parameter on a report: Employee
This parameter has a lot of possible values. Initially nothing is shown on the list and there is a textfield search parameter associated, that updates the Employee selection list with top n matches for the searched string.
If the entered search query is John Doe we can imagine that now the selection list shows:
John Doe
...
Xavier John Doesson
Now I can select as many items as I want from this filtered list, but if I want to select both John Doe and Alicia Keys happens the following:
First when I enter the search string "John Doe" the selection list gets populated accordingly
I select John Doe - OK
I enter search string "Alicia Keys", the selection list gets populated also
Selection of John Doe is gone - I want to be able to select both Alicia and John at the same time, but I don't want to go through a thousands of names long selection list
Update:
Forgot to mention that we have an OLAP cube in the background with dimension 'Employee'. This dimension is used as the source of the parameter and the param dataset uses MDX to fetch the values, therefore the SQL solution cannot be applied here.
The current solution creates an custom set with MDX Filter and Head functions and then this set is used in the ROWS-part of the MDX query.
Here is how the set created:
SET setEmployees AS {
HEAD(
FILTER( [Employees].[Employees].ALLMEMBERS,
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch,1 >= 1 )
)
,100)
}
Basically the problem with this solution is that how do you add multiple search strings to the instr function
Is there a common solution to this kind of situation? Am I approaching the problem from wrong direction?
What you could do is make the search parameter more flexible, so you can handle input such as:
John OR Jane
If "OR" queries are more common than "AND" queries you could support it with queries such as:
John Jane
Note that this may throw people off, because the search features they're used to (such as Google search) typically tend interpret multiple words in the "AND" sense.
Anyhow, the tricky bit of course is the SQL behind the Employee data set. This should use the search parameter in a more flexible way. You haven't specified how that's currently working, but I imagine you may be using something like:
WHERE Employee.FullName LIKE '%' + #SearchParameter + '%'
You would need to extend that to support "OR" queries. There's a whole range of solutions for that, from quick 'n dirty handmade SQL (e.g. string split combined with WHERE...IN) to full-text querying. Choose a solution that's best for your situation.
If you have a fixed number of search terms than you can do something like the following.
FILTER( [Employees].[Employees].ALLMEMBERS,
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch1,1 >= 1) OR
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch2,1 >= 1)
)
Even if you can do that, I do not recommend it. You don't have the luxury to index Analysis Services like you do SQL. A better possible approach would be to query your data warehouse for the employees and return the appropriate keys, and then filter by those keys in your MDX statement.

Returning specific field from a matching record

I'm still a newbie at Access 2007, but I feel I am missing a understanding of a concept, when it comes to using user input from an unbound text box.
I'm trying to have the user input the record number (i.e. A12) and return another field in the matching record (such as the record status like "Opened")
I'm fiddling with DLookup to see if it will work through that method but no luck yet.
I may look into SELECT - SQL, but I haven't used that function yet and not sure if that will give me the result I'm looking for.
If this is something elementary to access programming (or databases in general), please let me know where I can read up on this.
I am currently using the MSDN website, but examples go much further to play with.
Edit:
My DLookup so far, which happens after update from user on Text12
Me.Text14.Value = DLookup("[RecordStatus]", "Orders", Text12.Value)
Thanks
Look closer at the third option (Criteria) in your DLookup() expression. You gave it only Text12.Value, which I assume is a string value like "A12".
The Criteria parameter should be like a WHERE clause in a query, without the word WHERE. IOW, some field's value = "A12". If that field is named "record_id", try this:
DLookup("RecordStatus", "Orders", "record_id = '" & Me.Text12 & "'")

How to simulate a Group Header in an Access Continuous Form?

I have a form (not a report) in Access displayed in Continuous View that has alot of repeat data. i.e. it looks like:
State Names
FL Abe
FL Bart
FL Charlie
GA Deleanor
GA Mary
This needs to be interactive (there's some command buttons on each row as well as in the form header), but there's alot of repetitive data. Is there a way to add a group header by state? i.e. make it look like:
State Names
FL
Abe
Bart
Charlie
GA
Deleanor
Mary
I found a number of problems with the solutions posted. Most obviously there are issues (as noted) if there are duplicate entries. But I found there was a deeper issue which is that you can't do this and still sort the data on yet another field (suppose you wanted to sort by the date by which each name was first registered in each state, and yet NOT rank them that way).
A better solution is found in the Using Code section of the Microsoft KB:
http://support.microsoft.com/kb/q101081
The code from that section retrieves the actual data from the Previous field, in whatever sort order you define.
Computationally this can be a bit intense, so it works only for small datasets, but I achieved good results by first testing the function:
=PrevRecVal([Forms]![myForm],"ID",[ID],"Names")=[Names])
then putting it inside the IIF function:
=IIf(PrevRecVal([Forms]![myForm],"ID",[ID],"Names")=[Names],"",[FullName])
Have you looked at subdatasheets? If you have a state table (or just query your existing data for the unique states), you could use that in a non-editable parent datasheet, and then the subdatasheet would display the people data, and you could make it editable.
I'd implement this with datasheet forms, not with the actual table or query datasheets. This gives you a lot more control over the subdatasheet linking and formatting, as well as making interacting with the datasheet events easier (it can be done with a table or query datasheet, but only through Screen.ActiveDatasheet.
The closest I can get is to add a field to your form's record source which numbers each row within a group. Then you could add a text box in the detail section of your form with this expression as its control source.
=IIf(rank = 1, [State], ""]
The text box would display the first occurrence of each state, and a zero length string otherwise.
I tested with this query for the record source.
SELECT
m1.state,
m1.names,
(
SELECT Count(names)
FROM MyTable AS m2
WHERE
m2.state=m1.state
AND m2.names<=m1.names
) AS rank
FROM MyTable AS m1
ORDER BY m1.state, m1.names;
And it worked, but is not editable. If you need to be able to edit, try a query which uses DCount to generate the rank.
SELECT
m1.state,
m1.names,
DCount("names", "MyTable",
"state ='" & state & "' AND " & "names <= '" & names & "'") AS rank
FROM MyTable AS m1
ORDER BY m1.state, m1.names;
Both those queries give this result set with your sample data:
state names rank
FL Abe 1
FL Bart 2
FL Charlie 3
GA Deleanor 1
GA Mary 2
Note, I assumed unique combinations of state and name.