How to find similar records in ms access database compared to a specific record in the table - ms-access

I want to find the latest record of each patient and
compare the columns of that record to another record of a specific patient ID
Bring out the similarities
and group the records according to the percentage similarity value
So I want to see patients who have most similar records to that specfic patient to come on top and the rest follows.
Patient record

In short, sort by a calculated variable. Here is the query and table structure I used:
In my first definition of similarity I weighted each test equally:
CalculatedSimilarity: IIf([TestResults]![Test1]=[TestResult1],1,0)+IIf([TestResults]![Test2]=[TestResult2],1,0)+IIf([TestResults]![Test3]=[TestResult3],1,0)
in my second definition of similarity I doubled the value of the second test and ignored the 3rd:
CalculatedSimilarity2: IIf([TestResults]![Test1]=[TestResult1],1,0)+IIf([TestResults]![Test2]=[TestResult2],2,0)
to display as a percentage just divide by the weighted number of tests included.
When run against patient 5 who had "S" results on all tests the result is:
If you have many tests it would be better to construct the query with vba rather than the designer. this next step gets around a designer bug by linking the query to normally invisible text boxes.
the combobox rowsource is set to:
SELECT Patients.PatientID, Patients.FirstName, TestResults.Test1, TestResults.Test2, TestResults.test3 FROM Patients INNER JOIN TestResults ON Patients.PatientID = TestResults.PatientID;
have the combobox set the invisible textboxes
Private Sub cmbPatient_AfterUpdate()
'access designer can't see the column property. workaround by setting normally invisible text boxes
txttest1 = cmbPatient.Column(2)
txttest2 = cmbPatient.Column(3)
txttest3 = cmbPatient.Column(4)
similarity = cmbPatient.Column(5)
Me.Requery
End Sub
change the query parameters to reference the textboxes
CalculatedSimilarity: IIf([TestResults]![Test1]=[Forms]![Patients]![txttest1],1,0)+IIf([TestResults]![Test2]=[Forms]![Patients]![txttest2],1,0)+IIf([TestResults]![Test3]=[Forms]![Patients]![txttest3],1,0)

Related

SSRS Parameter select All with SSAS connection

I have a dimension in my SSAS model called Customer, I added the parameter to the report for "CustomerNumber", however, I don't want to have a drop down list of customer numbers (Over 5000 customers), So i set the available values to none and default values to none. and set the following into the Parameter Expression of the Dataset:
=IIF(Parameters!CustomerCustomerNumber.Value = "%",
"[Customer].[CustomerNumber].[All]",
"[Customer].[CustomerNumber].&[" &
Parameters!CustomerCustomerNumber.Value & "]")
So what I'm trying to achieve is either enter a single customer number into the parameter text box and receive all records for that customer from the dataset or if you want all customers data just enter %.
My expression above works when entering a customer number but it doesn't when I select all. I suspect the [All] doesn't work how I think. It shouldn't be too hard to do what I have mentioned. Will browse around for answers and post them up.
Cheers
Try this instead .All
[Customer].[CustomerNumber].ALLMEMBERS
If I understand correctly, .Allmembers gets the invidiviual members within the hierarchy whereas .All points to the collection.

What ID does a ComboBox reference?

I am attempting to maintain and fix a horribly out-of-date CRM designed by an ex-employee ~4-5 years ago in Access 2007. I have brought it into Access 2013 and fixed a ton of stuff up, but I am still running into many problems.
I spent a good 4 hours today attempting to figure out why certain values didn't line up. These values were being pulled from a SELECT statement on a Combo Box over a stored Query which simply returns a table with a few extra rows. Great.
However this value (a number) doesn't appear to correlate with what we expect. I enter in one value, save the ticket, and a completely different value gets stored into the table. Opening up the ticket, I see the value that I expect. Digging deeper, I found the following difference:
Set value_1 = Me.RegistrationID // What's being stored in the table
Set value_2 = Me.RegistrationID.Column(0) // What we expect
Surprise surprise! This is a Combo Box and some value is being stored in the table. The Control Source is "RegistrationID" and the Row Source is the query in question.
However I do not know what it is! This specific value correlating to the Combo Box appears to pull the correct data when we later open the tickets. However I have a strong feeling that this could be why many tickets from before one of the rows was deleted all appear to have invalid RegistrationID's.
How badly can this break?
How easily can we correct tens of thousands of tickets?
How can I fix this to store the correct value?
This is what I expect is happening.
Your combo box row source is based on a Select query which returns and displays multiple rows. For example:
Select RegistrationID, CustomerID, CustomerName From MyTable;
The Control Source for the combo box is bound to RegistrationID which is part of the Forms Record Source.
The issue is the bound column. If we set the bound column in our example to 1, then we get the behavior your are describing with:
Set value_1 = Me.RegistrationID - Set's value to CustomerID (may appear correct)
Set value_2 = Me.RegistrationID.Column(0) - position 0 from our query (RegistrationID)
Further building on our query example, you can say:
Me.TextBox1 = Me.RegistrationID.Column(0) - RegistrationID
Me.TextBox2 = Me.RegistrationID.Column(1) - CustomerID
Me.TextBox3 = Me.RegistrationID.Column(2) - CustomerName
The RegistrationID is what normally should be stored in the table.
As long as your form shows any values that directly relate to this RegistrationID you're fine.
I would start by checking to see under the format setting to see if column widths are set properly and I would also check under the data section to see if the bound column is correct. I might also throw in an after update macro/vba sub routine that saves the record. Hope this helps.

List box and Option group filtering 3 different rows in MAIN list box in MS Access 2013

I've been struggling with the following for a while and would be more than happy for some brainpower ;)
I have an Advanced filter form, which filters through orders via many different filters, currently the one that I can't make function is the following:
I have 4 controls on a form (all unbound):
ogProductType - option group that allows you to pick from 3 types of products
lbAllProducts - list box displaying all types of products. It has 2 rows, and gets filtered by tbSearchProducts which searches by the name of the product, but the lb is bound by the first row which is the product code. The filter is done by inserting criteria into the name row:
"Like "*" & [tbSearchProducts] & "*"".
tbSearchProducts - text box for searching the product by name. Has requery for lbAllProducts OnChange.
Main orders list box - lbOrders - which has many rows. The ones we care about in this case are ID; eProductCode; fProductCode; kProductCode. It is supposed to display all IDs of all orders where the filters are true (all orders where type 1 product is bought). In the query builder I have the following code as criteria for each them:
In lbOrders:
for eProductCode row
IIf([ogProductType]=1 And Len(Nz([lbAllProducts]))>0;[lbAllProducts];"")
for fProductCode row
IIf([ogProductType]=2 And Len(Nz([lbAllProducts]))>0;[lbAllProducts];"")
for kProductCode row
IIf([ogProductType]=3 And Len(Nz([lbAllProducts]))>0;[lbAllProducts];"")
I want the Main list box to be filtered depending on what type of product was chosen (eProductCode is chosen with the option group set on First option = 1; fProductCode = 2; kProductCode=3), but ignore the other 2 rows totally. Sadly, with that false statement saying the criteria for the field is "", in case it was not chosen via the option group, it doesn't work.
How can I stack 3 criteria, all taking values from the same list box, but only if option group is the right on, without them interfering with each other?
I tried with "*" in false and it doesn't work...
Any ideas?
I've solved it :)
You simply never use the criteria to filter the 3 rows... You just use the field itself to load the proper row that you need and put in criteria...
Here is the code for the field:
Expr1: IIf([obProducts]=1 And Len(Nz([lbSearchProduct]))>0;[tblOrders]![еProductCode];IIf([obProducts]=2 And Len(Nz([lbSearchProduct]))>0;[tblOrders]![fProductCode];IIf([obProducts]=3 And Len(Nz([lbSearchProduct]))>0;[tblOrders]![kProductCode])))
And in criteria for that row I set the list box that has the bound column for product code lbAllProducts

Access: Fill a combobox with selections from another field

I'm just learning how to use Access and while I've managed to muddle my way through most of what I'm trying to do, there's something I haven't been able to figure out how to do yet.
I have two forms and corresponding tables. In frmProducts is ColorOptions, a multi-select combobox containing a list of possible color options for a product, and Design, a text control for the name. In frmCustomers is OrderDesign, a combobox with a list of items from tblProducts, and OrderColours, a combobox.
Now, this is the problem: I want OrderColours to display list of the color options in tblProducts, but I can't figure out how. I can get it to display the value, but it's not a list of items, just one entry with the 'list' (e.g. a single entry reading "Brown,Red,Green"). I want the user to be able to select a single item from that subset.
Ideally I'd like to do this without messing with VBA or any advanced SQL, but if that's not possible then that's fine as well. I think the issue may be that the Colours field which contains the colours for that product is stored as text, but I'm not sure how else to store it as there's no 'array' or 'list' option for datatypes.
Sorry if I haven't been clear enough, or if this is posted in the wrong sub. I'm a beginner in Access, so I may have not been clear enough or used the wrong terminology. Any help would be much appreciated.
I'm not quite sure I understand exactly how you want this set up, so I'm assuming the following. Please correct me if this is not right:
tblProducts contains (at least) the two fields productDesign and productColour
It is possible for there to be multiple records in tblProducts with the same productDesign but different productColour (different colours of the same design)
There is another table, tblCustomers, in which each record contains a productDesign and one of the corresponding productColours.
So you need the combobox OrderColours to display a list of the possible productColours for the selected value of productDesign in OrderProducts.
Now, set up combobox OrderDesign as follows:
Row Source Type: Table/Query
Row Source: SELECT DISTINCT tblProducts.productDesign FROM tblProducts;
and OrderColour:
Row Source Type: Table/Query
Row Source: SELECT tblProducts.productColour, tblProducts.productDesign FROM tblProducts WHERE (((tblProducts.productDesign)=[Forms]![frmCustomers]![OrderDesign]));
Column Count: 1
and give OrderDesign the following event AfterUpdate:
Private Sub OrderDesign_AfterUpdate()
Me.OrderColour = Null
Me.OrderColour.Requery
Me.OrderColour = Me.OrderColour.ItemData(0)
End Sub
You may well also need to consider what happens when moving between records, if your comboboxes are bound:
Private Sub Form_Current()
Me.OrderColour.Requery
End Sub
in the Form_Current event should do the trick.
Read this for details.

DSum returning number of rows instead of total value

I have the following code attached to a text box in a form:
=DSum("[subform].Form![POINTS]","ATTENDANCE","[subform].Form![EMPLOYEE NO] = [EMPLOYEE NO]")
Ideally this would yield the total amount of points accrued by the employee we are currently searching for. However, what I am getting is the total sum of rows in my table.
Does anybody have any idea of how I could get the total sum of the values instead of the number of rows?
Thanks
If you want to get the total from a subform, and your subform in in sync with the main one, it will be much more efficient to procede this way:
create txtTotalPoints textbox = sum(Points) in the footer of your subform
refer to that control from your main form: txtMainResult =subform!form!txtTotalPoints
Hide txtTotalPoints (or the footer itself)
That will generally be much faster.
As far as I know, the Domain functions such as DSum, DLookup, DCount etc. are used to lookup and return values from a table. The first argument is the field, the second the table, and the third is the criteria or WHERE statement that makes sure you get the correct set of records. Your first argument refers to a form's field. I think this is incorrect. Your first item in your WHERE statement is also a form field. I this this is also incorrect. You need to try something like this instead:
=DSum("POINTS","ATTENDANCE","[EMPLOYEE NO] = " & [subform].Form![EMPLOYEE NO])