PowerApps formula for matching records from a drop down - dropdown

I'm trying to build a login form that performs a simple check against the user's PIN. The pin in stored in the database as a field in the Person entity (table).
I have a Team entity that allows the Person to select the Team they are on from a dropdown list of all Teams. The Person entity dropdown then populates based on the Person's TeamID. The User selects their Name and enters a PIN number in the txtPinNumber textbox.
The Login button is hidden by default and should only have visible = true when the pin entered into txtPinNumber is the same as the PIN field in the database.
I have the visible property of the btnLogin button set to
If(txtPinNumber.Text=Filter(Personnel,ddResponder.Selected.PIN),true,false)
However, I'm getting an error of unspecified type. Is it because I'm trying to check the entered PIN against a filtered datatype?
Any ideas on how to fix this error?

It looks like you're having difficulty because of your usage of the Filter() function. Filter() returns a table with all of the rows that meet a given criteria. However, it seems that ddResponder.Selected.Pin is the PIN you are seeking to match. If this is the case, you can simply have the visible property set to:
txtPinNumber.Text = ddResponder.Selected.Pin
If, however you need to do a search in your table to find the relevant PIN, you will instead want to use the Lookup() function.
You can see the documentation for these functions here:
https://powerapps.microsoft.com/en-us/tutorials/function-filter-lookup/
The Lookup() function will return the first matching row based on the criteria you provide, otherwise it will return a blank. You can use this with the IsBlank() function to determine whether or not to display the button.

Related

Getting a type mismatch but combo box still searches and displays data. ID column is being used to pull through Name but doesn't work

Error popup after click ok on type mismatch
I am using a combo box to search for records and it is telling me I have a type mismatch. I have been unable to find where this mismatch would be. The combo box still performs the desired function of selecting all records based on their "region"
I am using an ID field which is selected using the combo box but I want to pull through a name as well so I have input an unbound textbox and used VBA on change in the ID to update the name to the corresponding ID in the unbound textbox
Form
For privacy reasons I snipped around some of the other fields showing data.
The VBA in the on_change event in ID goes
Private Sub txtSupplierID_Change()
Me.txtSupplerName.Value = Table("tblSuppliers").SupplierName
Where Table("tblSuppliers").ID = txtSupplierID
End Sub
I'm aware this code could be very wrong but I could not find anywhere else that showed me how to do what I was trying to do. Any suggestions on how to actually do it would be appreciated. If I have not been as detailed as needed or yo have any questions please ask.
Edit for Clarification:
The form is not being used to save data. It is only being used to display data and issue an output to a report.
Code is not just wrong, it is nonsense. Cannot reference a table object like that. And that Where usage is not valid. One way to pull value from a table is with DLookup domain aggregate function. Advise use AfterUpdate instead of Change event.
Private Sub txtSupplierID_AfterUpdate()
Me.txtSupplerName.Value = DLookup("SupplierName", "tblSuppliers", "ID = " & txtSupplierID)
End Sub
Might want to correct textbox name from txtSupplerName to txtSupplierName.
However, should not save both supplier ID and supplier name into this table. There really should be no need for this VBA. Just put DLookup() expression in a textbox ControlSource. For other methods of pulling the supplier name to form, review answer in MS Access Identical Comboboxes for Autofill

How do I validate a Form input field with a Table row value in microsoft access?

I am having issues with setting a Validation rule in Access.
I have a database with the tables Clients, TypeClient, Sales, SalesList, Items.
I have a form for Sales, with a sub-form SalesList inside which has a relationship with Items in order for me to put several stock items in Sales instead of only one item.
Inside Sales table is ID, Date Sold, ID Client.
Inside SalesList is ID_List(referenced to ID in Sales), ID_Item(referenced to ID in Items), Quantity.
Inside Items is ID, Name, Stock(how much we have in stock), Price
The issue is that I am trying to validate the data I enter in the sub-form Quantity field to be higher than 0, but no higher than the available stock.
The issue is that I have tried using the expression builder to get the value from a calculated query that has 2 fields - the ID and the value for that id, with criteria that is for the ID to get it from the main form, the sub-form, the combo box input and the query works.
But when trying to get it like this:
It shows an error "The expression [Query bla] you entered in the form control's ValidationRule property contains the error The object doesn't contain the Automation object 'Query bla'".
I tried using directly the table Value(but it won't work anyway as it doesn't know for which field to get the stock value from), still the same error. I guess it can't reference to anything else? Normal validation rules work, but I want to validate it not to exceed the value of the available stock for the item I am selling now.
Nowhere on the internet there is a tutorial how to do it with expression builder. How do people validate their fields then?
It doesn't stop me in this case to sell 200 items when I currently have stock of only 2 of them, for example.
Note: I have tried DlookUp in expression builder, straight up tells me No.
Sample wrong validation rule expression builder code:
<=[Query bla]![Stock]
<=[Items]![Stock]
I am currently using VBA and fetch the record I need(the current stock) with one of the following and my unbound text is changing on every subform to the same, it shouldn't happen like that. What can I use to populate a field for each record uniquely:
Private Sub ID_Product_IZBOR_Click()
'Me.Stock_ValueField = DLookup("[Nalichnost]", "Stoka", "[ID]=" & Me.ID_Product_IZBOR)
Me.Stock_ValueField = Me.ID_Product_IZBOR.Column(2)
End Sub
Partial solution: I created a new Dim as Integer and fetched the records based on the ID provided by the field in the form and used BeforeUpdate to validate the current stock. Unfortunately the only way to see the current stock level is to click on the combo box where you choose your product and check the column for that one, it doesn't show anywhere else :(
Don't use the expression builder (I NEVER do) - just type the needed expression in property.
>0 AND <=DLookup("Stock", "Items", "ID=" & [ID_Item])
Another approach is to return Stock in textbox ControlSource then ValidationRule references that textbox. Also, user can then see the quantity limit. Methods of pulling the Stock value from Items table:
include Stock field in Items combobox RowSource - textbox then references column by its index (index begins with 0): =[cbxItems].Column(2); VBA may be needed to Requery combobox after record entry/edit is committed to table.
include Items table in form RecordSource - bind textbox to Stock field (Locked yes and TabStop no)
DLookup() expression in textbox ControlSource
Use ValidationText property to give users a custom message.
However, ValidationRule will not prevent user not entering any value if they skip the control. If you want to make sure a value is entered, either set field as required in table or use form BeforeUpdate event to validate record data.

How to write correct field criteria to get rid of the 'enter parameter value' erro?

PICTURE OF QUERY :
I'm plotting graphs for 10 machines (machine 1, machine 2,...) performance -
average vs date graph.
User shall select the machine from a combobox (i made the values obtained from query, or should I make it from the table?) and set it to contain unique values only.
After selecting the machine, user shall click OK button. and a graph of the selected machine should be displayed in a new form.
Problem is, every time I click OK, it prompts me with the ENTER PARAMETER VALUE Forms!ViewReport!Combo9.
After I enter "machine 1" in the ENTER PARAMETER VALUE, it displays the graph correctly. I am expecting the graph to be displayed directly without the error.
The dialog appears because the query has no access to the field Combo9. Probably your form is not open or ViewReport is a subform, in this case, the reference to Combo9 should be different. Check, for instance, this giude for controls references.
But the most reliable method is to create a public function in the standard module, which should return the value from the desired form's field. It can check if the form is open and return the default value if the form is not available or the value is not selected. This function can be used in queries as criteria or in calculated fields.

Gray out a form row's (detail's) button conditionally with VBA code

I have a standard form in MS-Access which lists a bunch of orders, and each row contains order no, customer, etc fields + a button to view notes and attached document files.
On request from our customer we should gray out the button btnAnm (or check or uncheck a checkbox) depending on a calculation from two queries to two other tables (a SELECT COUNT WHERE and a check if a text field is empty).
I've tried btnAnm_BeforeUpdate(...) and btnAnm_BeforeRender(...) and put breakpoints in the subs, but none of them trigger. The same if I use the control Ordernr instead of btnAnm.
I'd like a function in the Detail VBA code to be triggered for each "Me." (row) so to speak, and set the row's control's properties in that sub.
What do I do? I've looked at the help file and searched here.
*Edit: So I want to do something that "isn't made to work that way"? Ie. events are not triggered in Details.
As an alternative, could I base the value of a checkbox on each line on a query based on the 'Ordernr' field of the current row and the result of a SELECT COUNT from another table and empty field check?
Do I do this in the query the list is based on, or can I bind the extra checkbox field to a query?
A description of how to do this (combine a COUNT and a WHERE "not empty" to yes/no checkbox value) would be perfectly acceptable, I think! :)*
You cannot do much with an unbound control in a continuous form, anything you do will only apply to the current record. You can use a bound control with a click event so that it acts like a button.
Presumably the related documents have a reference to the order number that appears on your form, which means that you can create a control, let us call it CountOrders, with a ControlSource like so:
=DCount("OrderID","QueryName","OrderID=" & [OrderID])
The control can be hidden, or you can set it up to return true or False for use with a textbox, you can also use it for Conditional Formatting, but sadly, not for command buttons.
Expression Is [CountOrders]>0
You can also hide the contents and add a click event so that is acts in place of the command button. Conditional Formatting will allow you to enable or disable a textbox.
As I understand your question, you have a continuous form with as command button that appears on each row - and you'd like to enable/disable the button conditionally depending on the contents of the row.
Unfortunately you can't do that. It seems that you can't reference the individual command buttons separately.
Having wanted to do something similar in the past I came up with two alternate ways of setting up my interface.
Put a trap into the onClick code for the Button. Which is icky, because it is counter intuitive to the user. But it gets you that functionality now.
Move the command button (and editable fields) up into the form header, and make the rows read only. Your users then interact with the record only in the header, and select the record they want work with in the list below. As I recall this is known a Master-Detail interface.

Conditional default values in MS Access

I'm using MS Access 2007. I have a form with several phone number fields (cell, home, work, primary*). The data source for all of these fields comes from a Customers table.
Basically, what I am trying to do is establish a set of default values for the primary* field. I would like to accomplish something like this:
If [cell] <> Null:
primary* = [cell]
elif [cell] Is Null and [home] <> Null:
primary* = [home]
elif [cell] Is Null and [home] is Null and [work] <> Null:
primary* = [work]
I know this isn't very logical code, but I hope you can see what I'm trying to do here. I just want the primary* field to default to the cell number if there is one, then the home number if there is no cell, and finally the work number if it's the only one available.
Is there a way to do this with the Properties panel in Access?
The default value property for a data control is evaluated/applied at the instant a new record is started. It's probably obvious that happens before the new record has been INSERTed into the table. Perhaps less obviously, it happens before the user has entered any data into the new record. So even if it were possible to have the default value based on another field value ... the other fields would be Null at that point, unless they also had a default value assigned.
In a different situation you might consider the form's before insert event to assign whichever control value you want to the target control. However, that's not such a great fit if you want the user to change the default primary value before the record is saved.
Think I might fall back to using the after update events on the individual phone number controls. So for [cell] after update, you could use:
If IsNull(Me.primary) Then
Me.primary = Me.cell
End If
And similar for the others.
After the user or the code has assigned a value to Me.primary, it will be left unchanged unless the user changes it.
If you don't mind your control being read only, you could simply use a expression as your source control. Something like this :
=iif(IsNull(Cell);iif(IsNull(Home);Work;Home);Cell)
If you want the control to be editable, you'll need to dynamically change the control source in the code behind on the onActivate event I guess (I haven't tested that).