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.
Related
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))
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.
I'm sure that this is a basic question but I'm struggling to get to grips with Access.
In my case I have two tables: Student and Subject, linked by a junction table, StudentSubject. Student and Subject have a many to many relationship, as one student can study multiple subjects, and one subject can be studied by many students.
What I don't understand specifically is how to input data so that each student can study more than one subject. I've created a Form with a Subform that looks like this:
When I try to input anything into the "SubjectName" field, it says "Field cannot be updated". If I press "Okay" the message goes away and I can type something in the field, but as soon as I try to put something else in the record below for "Subject", the same error comes up. Then when I press the arrow to go to the Next Record on the Form, and save the form, nothing has changed in any of the tables.
Here are the three tables and their relationships:
I'm not too sure what I'm doing wrong here, but the end goal is that I can input a student and also input all of the subjects that they are doing, so that each student's individual list of subjects is stored alongside their name. I don't know where the "Field cannot be updated" error is coming from.
Could anyone advise?
You need 3 forms:
One form for students,
One form for subjects
One form for the Student-Subject table
The Student-Subject form will be a sub-form in both of the other forms. This form can have combo-boxes for the student and subject. For example, here's what editing a student might look like:
This way, you can easily add new subjects a student is taking (and similarly, add new students that are taking a subject).
Note that both the Subject and Student columns are being shown. What I've done in the past is have a bit of VBA to hide the appropriate column based on what the parent form is:
Option Explicit
' note that this code goes in the Student-Subject form.
Private Sub Form_Load()
If Me.HasParent Then
Me.cboStudentID.ColumnHidden = (Me.Parent.Name = "frmStudent")
Me.cboSubjectID.ColumnHidden = (Me.Parent.Name = "frmSubject")
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''
Public Function HasParent() As Boolean
On Error GoTo err_handle
HasParent = Not Me.Parent Is Nothing
Exit Function
err_handle:
HasParent = False
Exit Function
End Function
This way, the appropriate column is hidden based on whether you're editing a student (and the Student column will be hidden) or editing a subject (and the Subject column will be hidden).
Typically you have two different views on such a multi to multi relation. One is you are in the student's view and the other is if you are in the subject's view.
In the case of the student's view you must create a form to edit the student's table and you have to add a subform to edit the detail data table, i.e. StudentSubject. This detail table has to be synchronized with your StudentID from the main form. Usually this is already done by the wizard. But please be aware that you have only the ids in the detail table. To display a readable information you need to change the text boxes to combo boxes and to bind the combo boxes to the underlying tables.
Because you have only numbers in the detail table StudentSubject you cannot input text directly into this box. If the SubjectName has not been registered in the table Subject you have to add the new entry before you can select this. To dynamically add a new text entry you may use the "Not in List" event to handle this.
Hi & thanks for reading/helping!
I have a simple table with email addresses and domain names. In an equally simple form I can list in a listbox the email addresses that go with each domain name using:
SELECT Emails.EmailAddr FROM Emails WHERE Emails.[DomainName]=Form![DomainName];
and it works perfectly. However despite trying every permutation going I CANNOT make the same thing work in a report :-( even if I try saving the form as a report. Can anybody help me understand why this doesn't work ...
SELECT Emails.EmailAddr FROM Emails WHERE Emails.[DomainName]=Report![DomainName];
If I omit the "Report!" then I get a list of all email addresses but with every other reference I get nothing at all or an error.
My forehead is bruised from banging it on the table!
Jimmy
The syntax for referring to report controls is the following:
Reports!ReportName!ControlName
You should be able to use that in your SQL clause.
I'm sorry if my question sounds confusing.I just started learning web2py recently,in this exercise I'm trying to make a simple users management webpage with the admin can assign the users theirs work lists,note and deadline
db.define_table('auth_manager',Field('name','string',requires=IS_NOT_EMPTY()))
db.define_table('manager',Field('user','string','reference user.name'),
Field('workname','text',requires=IS_NOT_EMPTY()),
Field('deadline','date'),)
db.manager.deadline.requires=IS_DATE_IN_RANGE(format=T('%Y-%m-%d'),
minimum=now,maximum=now+datetime.timedelta(60))
I thought of adding the manager's username in auth_manager table using appadmin's new record function.This is my user table
db.define_table('user',Field('name','string',requires=IS_NOT_EMPTY()),
Field('password','password'),
Field('workname','text'),
Field('deadline','date'),
format='%(name)s')
I wanted to insert workname and deadline into user table right after I add those form on manager but I couldn't find any other methods except the update or update_or_insert functions but both don't work because those fields can't be empty and their ids aren't the same value and multiple references to a single table don't work .
One last question,I want to use web2py's RBAC but the first & last name fields are often unnecessary if I want to use a full name field is there other way to do it?
Sorry for the long post,I hope I made my question clear.
You can use the tables from auth and let web2py to handle everything in between.
The following code should resolve your problem:
db.define_table('manager', 'reference auth_user'),
Field('workname', 'text', requires=IS_NOT_EMPTY()),
Field('deadline', 'date'))