ColumnHistory of a table field within a form - ms-access

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))

Related

Adding the info from one text field into another without erasing the info that already exists

I have an access database with two Long Text fields "QAComment" and "NoteComment." We have found that the NoteComment field is rarely used and we want to stop using it, placing the information that might go there within the QAComment Field instead. Every record currently has text in the QAComment field already. What I am trying to do is run an update query that moves the information from NoteComment and appends it onto the Information from QAComment - I cant lose whats already in there. I tried googling for a way to do this but it keeps sending me to basic update queries where the info would get replaced, not added onto. I thought it might be possible to concatenate the two fields together into a third field and then copy that info back to the QAComment field, using
Conc: [QAComment] & " " & "Note comments:" & " " & [Notecomment]
Which works, but I can't figure out how then to use that expression to record that information into the table. I thought I might be able to use the value of the concatenate in the Update, but I cant seem to figure out how to reference it. I also tried just putting the Conc statement in the Update To: but nothing seemed to happen. I'd appreciate anyone who can think of a way to do this.
Sounds like you're building the query in Design View. Switch to SQL View and paste in this text, substituting your table name in place of YourTable
UPDATE YourTable AS y
SET y.QAComment = y.QAComment & " Note comments: " & y.Notecomment
WHERE Len(Trim(y.Notecomment)) > 0;
You can switch back to Design View, if desired, to see how the query is presented there.

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.

compile error invalid outside procedure

I have a table in my Access database where I keep track of my jobs. I have a form based on a query based on this table. In my table there is a field called [file_path]. This is a field that controls a web browser on my form.
I would like this field [File_path]to be updated when I update my field [customer_Id] on the form. It should be updated to reflect the customer name together with the file path e.g. C:\Users\Windows8\Documents\Projects\Doe John.
How do I pull the [Customers]![Last_Name] and [Customers]![first_name] into my string in field [file_path]?
I think that I have to use VBA code, but not sure how. I have started with this:
Private Sub Customer_AfterUpdate()
Me.File_path = Me.Last_Name
End Sub
I know that this is a feeble beginning. Does someone know how to help me? Please tell me if my question is not clear.
Beside all this the above code is returning Invalid outside procedure in Private Sub Customer_AfterUpdate(). Why?
Me refers to the form. You are correct that using Me is best practice (speed, ease of coding, etc.), but when I was starting out or even now in a complicated application I like to write it out, because that reminds me not to make little mistakes like this. Or, maybe your memory is better than mine, in which case ignore and read on.
[file_path] is in the table, so you need to access it in the table. Your code looks for it in the form, and realizes that it isn't inside Me, and throws this error.
I am going to give you a line of code below that should be a good starting point for you, but I think you may need to examine your calling event. AfterUpdate is cool, because it just seems to happen automatically, but I don't think you want your field updated every single time anything in the whole "Customer" form is updated. If there is a specific textbox that is always updated last (last_name?), you could try that one instead, but I would be nervous about trying to remember to always make sure that was the last one that I updated... I mean, if one day I accidentally did the name before the customer_id, I would have some serious confusion on my hands later on. Might I suggest a command button, and using the Click event instead?
No matter what event you end up using, you really only need one line of code inside your event. There are plenty of ways of doing this. Might I suggest something along the lines of CurrentDb.Execute "update " & myAwesomeTableNameHere & " set file_path='"C:\Users\Windows8\Documents\Projects\" & forms("customers").controls("last_name").text & " " & forms("customers").controls("first_name").text & "' where customer_id='" & forms("customers").controls("customer_id").text & "'"
Now, a caution: data is precious, and beautiful. The names of the people who pay you are even more so. Changing data in a pre-populated table by free-typing into a textbox on a form sounds like disaster waiting to happen to me. If it were me, I would either 1)make backups very often (easist), or 2)validate your entries multiple ways before writing anything to the table.

Access 2002 - display text on form

I have asked two similar questions, neither of which have been written with the necessary precision I need, but both of which have been answered correctly. I apologise for this and I will attempt to ask the question again with suitable precision.
I have a form on which I am attempting to display information from several tables. The form is called contacts1. The main database table the form is based on is a customer table called contacts, and is keyed on contact_id. I use the form to display information relating to a contact. I want to also display the address of a contact (in a text field called concatAddress). The address information is in a database table called address, keyed on address_id, and has a foreign key relationship with the contacts table via contact_id.
I have an expression I am trying to use to display the address: =DLookUp(" [address]![address_line_1] & [address]![ address_line_2] & [address]![city]","[concatAddress]","[address]![contact_id]=" & [Forms]![contacts1]![contact_id]). This gives me an #Error on my form. I am unsure what is causing this error.
Why would my expression cause the error please?
Oh dear. I have the answer: I forgot to include the table the address data is coming from - I mistook the table name field for the field the data is going into. So, this works:
=DLookUp("address_line_1 &" "& address_line_2 &" "& city","[address]","[address]![contact_id]=" & Forms!contacts1!contact_id) (I added spaces between the address fields and the city).
I hope this helps someone - I've been playing with this for a while now.