Power apps. Retrieve values of record with multiple choices in SharePoint list column for a dropdown box - powerapps-canvas

For reference I have recreated this app https://www.matthewdevaney.com/make-a-power-apps-approvals-form/
I changed the equipment column to have multiple values and now some code dosent work because the entry is not a record anymore. I think it is a table now.
I have some code for e.g here;
ViewForm(frm_Request);
Set(varRequest, frm_Request.LastSubmit);
If(varRequest.Status.Value="Submitted",
Office365Outlook.SendEmailV2(
varRequest.Manager.Email,
"IT Equipment Request - Approval Required",
"An I/T equipment request was made for a "&varRequest.Equipment.Value&" by "&varRequest.Employee.DisplayName&". Click here to approve/reject the request."
)
)
at &varRequest.Equipment.Value& (.Value) has an error "expecting record value"
I tried changing this to concat(varRequest.equipment, Value & ",") But it seems to create errors when running the app
Is there a work around for this ?
Im very new to coding and power apps in general so sorry if this is missing any details.
Image of error when running the app after adding concat()

Related

ColumnHistory of a table field within a form

I am attempting to utilize an idea I have found within an Access template listed as "Asset Tracking." One of the forms, Asset Details, has a comment tab with two fields, New Comments (which is associated with a comments field in the sourced table), and Comments History, which features the following code in the Control Source:
=ColumnHistory([RecordSource],"Comments","[ID]=" & Nz([txtID],0))
The code allows one to enter information into the comment field that then updates the comment history with that comment once the form is saved and closed. This is based on the append only option being set to "Yes" under the Long Text format. The result would look something like this:
[Version: 12/18/2019 5:00:22 PM ] Jonathan's Law
[Version: 12/18/2019 5:14:13 PM ] Complete Last Interview
[Version: 12/20/2019 9:35:52 AM ] Hello Paul
[Version: 12/20/2019 10:00:31 AM ]
[Version: 12/20/2019 11:42:54 AM ] And then she got fired
[Version: 12/20/2019 11:44:07 AM ] And never rehired.
I have a database that I am initially developing for my agency for incident management (four tables: Investigations, Investigations - Target(s), Investigations - Victim(s), Investigations - Target/Victim Joiner. See this previous question for more details), and I saw that this code would be handy in identifying when an allegation changes (i.e., Neglect to Mistreatment) or to provide a comment box with comment history of my own within the forms developed. I attempted the code in my form and created a text box with the following code(s) in the Control Source:
=ColumnHistory("[Investigations - Target/Victim Joiner]","Offenses","[TargetID]=" & Nz([TargetID],0))
OR
=ColumnHistory([RecordSource],"Offenses","[TargetID]=" & Nz([TargetID],0))
Originally I tried to have either of these on the main form but I realized that the main form does not directly source the correct tables needed (I was getting a #Name? error and could not remedy it), but one of the subforms within the form did. I attempted the above codes in a text box within my allegationsubform and now receive a #Error code. I am really not sure how to proceed; I am looking for a way essentially to create an audit trail of changes to one's offenses (and eventually outcomes) as they are changed. I am wondering if the many to many relationship between victims and targets based on my arrangement is also creating issues (the TargetID and VictimID on the junction table are both PK's as part of the many to many); in which case, I am curious if something like the following code (it didn't work for me) would be on the right path:
=ColumnHistory([RecordSource],"Offenses","[TargetID]=" & Nz([TargetID],0) & "[VictimID]=" & Nz([VictimID],0))
Any help regarding this would be much appreciated; my entire Friday has gone into trying to identify an article that clearly explains where I am going wrong and none so far have helped me make the connection. All errors I have seen others correct are either the result of the code miraculously working without explanation of what was changed, or a minor grammatical error was present (i.e., missing quotes) in the code.
Sources of Research prior to asking question:
How do I display a memo field to a Form in Access
https://access-programmers.co.uk/forums/showthread.php?t=293527
https://answers.microsoft.com/en-us/msoffice/forum/all/creating-a-comments-history-box/56c1b861-f081-442c-aaa5-02b95eae14b9
https://learn.microsoft.com/en-us/office/vba/api/Access.Application.ColumnHistory
Need an " AND " in the criteria:
=ColumnHistory("YourTableName","Offenses","[TargetID]=" & Nz([TargetID],0) & " AND [VictimID]=" & Nz([VictimID],0))

MS Access popup form conditional on combobox value

I am working on a database to store a heap of animal behavioural observation data and am working on creating a form to input data (one of many forms). The main form feeds into a table called "FocalSample" and the subform feeds into a "FocalData" table.
This is the form at present
There will be multiple records in the subform to a single overarching sample, a sample is a 10 minute period and a single animals behaviour is documented over that 10 minutes, noting time in minutes and seconds to calculate duration of time spent in each behaviour.
I need popup forms to come up depending on what is selected in the "Behaviour Type" field of the subform, as the kind of data recorded for a "feed" observation compared to a "social" observation is very different. I have created separate tables for the different behaviour types of data and forms that are set as "popup" forms, but need help with the code to get it to do what I need! :P
I have been trying a variation of the following code that I found here (http://www.justskins.com/forums/pop-up-form-based-238440.html)
Private Sub Campaign_AfterUpdate()
Dim strFormName As String
Select Me.Campaign.Value
Case "In Honor", "In Memory"
strFormName = "HonorMemory"
Case "In-Kind"
strFormName = "InKind"
End Select
DoCmd.OpenForm strFormName, , , , , acDialog
End Sub
But I keep getting an error message after the first row.
Here is the error and code screen
Similar to the other forum link I attached, I also need the popup form to draw a lot of info from the main form, but I'd just be happy to be able to get the popup forms working at the moment.
Sorry for so much detail - I am in a remote area of Africa and only have limited access to internet so am trying to give as much info up front!
Example of popup form - you might be able to determine fields that will feed off the focalsample form
Another example of a popup form - different behaviour type to the previous
EDIT
I have jigged the code now based off previous response but am not getting a different error.This is the code with the error line highlighted - I am not sure what table name to add if any
Error code
The line Select Me.Campaign.Value should read Select Case Me.Campaign.Value.

Access 2010 - Bound Textbox - Only updating newest record created

I am trying to update the textbox for the current request that I have opened. After making changes to the bound textbox (regardless of the record number current being edited) it modifies the tblVendorRequests.VendorDiscussionNotes for the newest request created within the table.
My form is a Single Form
My record source for my form is a table (tblVendorRequests)
My textbox (txtVenConLog) is using tblVendorRequests.VendorDiscussionNotes as its control source
For instance, say I am trying to add notes "Hello World" to request number 242. Request 242's notes remain the same, but the "Hello World is added to the newest record instead (overwriting the existing text that was in the request).
I have done a good amount of searching on the topic, and have not found a satisfactory answer on why this would be.
Any ideas would highly appreciated!
I redesigned my form to split the functions into 2 separate forms and that seems to have resolved the issue. I believe the issue was that when I 'opened' a record, it was not behaving like it would if the record-opening function resulted in calling a form to open with specific criteria.

MS Access 2007 - controlling UI behaviour after attempt to insert duplicate record

Creating a simple UI using MS Access, hoping to do minimal actual coding (actually helping a friend who is not a coder).
Simplified requirement: Single table, primary key is phone number, lots of other non-mandatory fields. Display a form allowing just the phone number to be entered, if a record with that key exists display the full record, if a record with that key does not exist bring up an form allowing the other fields to be entered for this phone number and hence create a new record.
Q1: Any simple way to achieve this kind of function? Example?
We've got some of this going with a standard form, can execute code if insertion fails, but a standard dialogue box is displayed warning about the duplciate key violation.
Q2: How can we trap that attempted insertion, avoid having the dialogue come up?
You will have to get your hands dirty and write some code to get this outcome. A starting point would be something like this presto code. Post back if you get stuck on any of the parts.
If fCheckIfRecordExists(lYourKey)=True then
Docmd.OpenForm “frmEditExistingRecord”
Else
Docmd.OpenForm “frmEnterNewRecord”
End if
Public function fCheckIfRecordExists (lYourKey as Long) as Boolean
‘Code to check if a record exists, simple method is to use dLookup or a count SQL statement with the criteria as the key you are trying to find
End function
EDIT:
First things first make a form with 1 text box called txtPhone_number and a command button called cmdSearch.
Next put this bit of code in the module behind the form
Public Function fDoes_record_exist(strPhone_number As String) As Boolean
If DCount("Phone_number", "tblYour_table", "Phone_number=" & strPhone_number) > 0 Then
fDoes_record_exist = True
Else
fDoes_record_exist = False
End If
End Function
Next you need to put some code behind the click event of the command button. This code can be expanded on to check for a valid phone number later if you want
If fDoes_record_exist(Me.txtPhone_number) = True Then
DoCmd.OpenForm "frmShow_existing_record"
Else
DoCmd.OpenForm "frmEnter_new_record"
End If
That should set you on your way nicely but post back if you run into problems
Here is an overview of the process with Access logic:
You need an unboud control labelled Phone in the form header, where user will be able to enter the phone number to search. You need to use the After_Update event of that control to trigger your search. There will be a second Phone control, bound this time, in the Detail section of the form for effective data entry/update.
Use the Form_Error event to intercept the error message when user tries to save a duplicate key, in order to display a nice message, and eventually Cancel his changes.
The advice from Kevin Ross to use VB Code is clearly one approach, and I think is appropropriate if we anticipate less trivial requirements in future. However I'm in a situation where I'm helping someone with zero coding background and hence if possible I'd prefer to let them use simple Macros rather than full-scale VB.
As it happens the functionality I require can be implemented with just Macros, and it depends on the suggestion from iDevelop.
The outline of the solution I used:
Create an InitialEntry form with no association to any particular table, it has:
a data entry field for the telephone number
a read-only text box where I can display a message
a button labelled Add
a button labelled Show
I write three macros:
A macro AlreadyExists that displays a message saying "We already that one"
A macro NewEntry that opens a data entry form for my table, in Add mode, and which copies the phone number from InitialEntry!TelephoneNumber
A macro TestForExisting this uses a condition
DCount("*","MyTable","[PhoneNumber] = [FormPhoneNumber] " ) > 0
to control whether to execute AlreadyExists, and a similar test to control whether to call NewEntry.
While this is not as efficient as VB, it does seem to be understandable by a non-coder, so at least we can implement our application.

"No current record" after Cancel in combo_BeforeUpdate

I'm trying to prevent circular (or even cascading) references in my data, and it seems it's only working part of the time.
In Access 2007, I have the following table:
create table mfr (
mfr_id Autonumber,
mfr_nm Text(255),
mfr_is_alias_for_id Long Integer
)
I'm importing a bunch of data from Excel, and the mfr_nm is one of the columns from the worksheet. I can't control how data gets entered into Excel, so I want a way of capturing alternate spellings as being "really" same thing. So far, so good (I think...).
Now I've built a form off of this table. I've got a ComboBox for the alias--again, so far, so good. However, when I add this code to the BeforeUpdate event, things get "interesting" (error handling omitted):
If Not IsNull(cboMfrAlias) Then
If Not IsNull(DLookup("mfr_is_alias_for_id", "mfr", "mfr_id=" & cboMfrAlias)) Then
MsgBox """Alias for"" must not also be an alias.", vbExclamation
Cancel = True
End If
End If
This works exactly as I expect it to when the form is in Form View, but if I'm in Datasheet View my MsgBox is immediately followed by an Access-generated "No current record" error that is not caught by error handling within the BeforeUpdate sub.
Can I catch this error? Where?
Your dropdown list should filter out entries that are aliases. In other words, don't display a choice the user can't make.
You'd do this by simply eliminating from the dropdown the choices where mfr_is_alias_for_id Is Not Null.
I've implemented this in various guises and it works fine.
I'm addressing the "No Current Record" error part of your question, from so long ago. After checking google for an answer, I found this link which was helpful. However, instead of using NZ() to transform the troublesome binary field in an aggregate query, I used troublesomefield: IIF([troublesomefield] IS NULL,NULL,[troublesomefield]) and this worked to banish the error. So my solution is only a small variation on the original answer I found, but it gets around the error and let you keep nulls if you want to...