We are updating Access from Excel using linked tables and am having trouble with specific fields that are conditional. The files are linked using a unique field and it updates an existing record if found or adds a new one if not found. In most cases, it is a field to field match from Excel to Access and works as expected, but we have a number of fields that are conditional. We've tried a number of different options and cannot get it to work.
Scenario 1: Access has two email fields, say Email1 and Email2. Excel has one email field and a mailing list field. If the mailing list field is Yes then the email address goes to email1, if it is no then the email address goes to email2.
Scenario 2: Access has four Y/N checkboxes, which display True or False in the data, call these fields A, B, C and D. Excel has a single field with four possible entries "selection 1", "selection 2", "selection 3" and "Selection 4". If Excel is "selection 1" then A is true and B, C, D are false; if Excel is "selection 2" then B is true and A, C and D are false.
A snippet of the working code:
UPDATE AccessDB RIGHT JOIN [ExcelTbl]
ON [AccessDB].[MemberID] = [ExcelTbl].[MemberID]
SET [AccessDB].[MemberID] = [ExcelTbl].[MemberID],
[AccessDB].[First Name] = [ExcelTbl].[First Name],
[AccessDB].[Mid Initial] = [ExcelTbl].[Middle Initial],
[AccessDB].[Last Name] = [ExcelTbl].[Last Name],
When working on the scenarios above, we have tried If, Iif, Case and several other options and cannot get this to work. Any help is appreciated.
Related
Collecting responses from a Google Form, I have two categories for the name of the person responding and the title of the play they are to assess. In one category, "Board Members" have a dropdown list of their names and the titles of plays available for them to evaluate, whereas the second category is for "Guest Readers" to choose their name from a dropdown list and the more limited play titles for them to choose from. I have the form working fine, but the results in the Google Sheet are as shown on the tab "Form Responses 3" tab of this example sheet: https://docs.google.com/spreadsheets/d/1c9AK-Df-rgnNDKfeXRo0msoUHmVCIxs0EFD_HPDxWA4/edit?usp=sharing
I am trying to build a QUERY statement that produces the outcome on the "Assessments" tab of the same sheet.
My thinking thus far is that the values of the Columns to choose from in the "Select " section of the QUERY are dependent on an embedded IF statement something like:
=query('Form Responses 3'!$A$2:$G, "Select '" & if('Form Responses 3'!$C2<>'',"D, C, G Where not E <>''", "F, E, G Where not C <>''") &"'")
I'm not sure of many things here -- I am confident I am getting lost in the ' and " frames -- but most specifically, can I even make the dynamic callback to a cell within the dataset in the IF formula that will manifest in each row of the QUERY result? Am I making any sense at all?
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.
I am using MS Access 2016 in an attempt to create a Form-driven database.
Suppose I have 2 forms - enter data into several Text Box's on Form One, then another form where user can keep updating/changing the record over time to update current status for only specific fields.
The problem I am facing is that data entered into Form One is placed in Record 1 on my Table, while data entered into Form Two is placed in the next Record (Record 2).
Question: How can I create a string of Forms, but have the data inputted into each of those Forms show up on the same Record in the same Table?
e.g. Form 1 has following fields
Name
Date
Style of Cause
Court File number
Status: "Open", "Close", "Re-Open"
Action Required
File Closure Summary
(and more 39 relevant fields)
Form 2 (I need to update the same record for only selected fields )
Status: "Open", "Close", Re-Open"
Current Status Summary
Status Summary
File Closure Date
File Closure summary
Action Required
Key Lessons Learned
I am trying to write code for a data certification status combobox that will allow or not allow the user to change the status based on specific guidelines:
User may change status from Raw to Clean, no restriction
User may change status from Clean to Certified, no restriction
User may change status from Raw to Certified after answering yes to verify all necessary QA/QC has been done
User may change status from Clean to Raw, if answers yes to proceed and provides explanation in "Comments" field
User may not change status from Certified to Clean, or from Certified to Raw
I assume I would use a Select statement where Case 1 = Raw (ID=1), Case 2 = Clean (ID=2), Case 3 = Certified (ID=3). The IDs 1, 2, and 3 are the ID values in the lookup table for the data certification status'. What I'm struggling with is how I set the "Before" value to compare to the "Current" value, when the user has already selected a different value.
Also, I'm using the "OnChange" event. But wondering if "BeforeUpdate" or "OnDirty" events would be better.
Any help would be greatly appreciated.
use "BeforeUpdate" Event on combox
If Me.Combo3.OldValue = 1 And Me.Combo3.Value = 2 Then
Dim x
x = MsgBox("all necessary QA/QC has been done? ", vbYesNo)
If x = vbNo Then
MsgBox "any thing you want to write"
Cancel = True
End If
End If
I am trying to create a form in access that has a dropdown at the top and will populate the rest of the form with the record that corresponds to what is chosen.
I have looked at 2 different guides online but both point to older versions of Access and I think I am missing something.
So. The order that I did everything:
I went to the table for the form. And I clicked Form. This made a quick form with all of the fields as text boxes.
I deleted the field that will be the dropdown and I put in a dropdown canceling the wizard
In the data section for the dropdown. I edited "Row Source" to select the field that will be in the dropdown and the unique ID, in that order.
I set the bound Column to 2 (I have tried both)
I set the name of the Combo Box to "TitleSelector"
In Form Settings. For "Record Source". I have "[forms]![Edit Piece].[TitleSelector] & "*" in Criteria for "ID". I also have the rest of the fields in the Query listed
I added the "me.requery" to on change
Not sure if it means anything. When I was typing in the Criteria for "ID" it did not show "TitleSelector" in the drop down.
I am using Access 2010
Edit:
My Problem -
The dropdown itself shows everything correctly. However nothing happens when I choose something
Edit:
SELECT Pieces.ID, Pieces.Title, Pieces.Composer, Pieces.Instrumentation, Pieces.Location, Pieces.Location_2
FROM Pieces
WHERE (((Pieces.ID)=[forms]![Edit Piece].[TitleSelector]));
Edit:
Here is a link to a copy of my database: https://www.dropbox.com/s/tpnqm686tj653fg/Trisha%20Database.accdb
Adding the me.requery to the ON CHANGE EVENT
(select CODE BUILDER - and enter the me.requery there) should work.
I have downloaded the sample file. Your problem is that the Record Source for the [Edit Piece] form is set to...
SELECT Pieces.ID, Pieces.Title, Pieces.Composer, Pieces.Instrumentation, Pieces.Location, Pieces.Location_2 FROM Pieces WHERE (((Pieces.ID)=[forms]![Edit Piece].[TitleSelector] & "*"));
...and the & "*" at the very end is causing the query to return no records. Removing that last bit so the Form's Record Source is...
SELECT Pieces.ID, Pieces.Title, Pieces.Composer, Pieces.Instrumentation, Pieces.Location, Pieces.Location_2 FROM Pieces WHERE (((Pieces.ID)=[forms]![Edit Piece].[TitleSelector]));
...gets your form working.
Edit
To have your form display information from the related tables (instead of just the foreign key values from the [Pieces] table), change the Record Source of the Form from...
SELECT Pieces.ID, Pieces.Title, Pieces.Composer, Pieces.Instrumentation, Pieces.Location, Pieces.Location_2 FROM Pieces WHERE (((Pieces.ID)=[forms]![Edit Piece].[TitleSelector]));
...to...
SELECT Pieces.ID, Pieces.Title, Composer.Composer, Instrumentation.Instrumentation, Location.Location, Location_1.Location AS Location_2 FROM (Location INNER JOIN (Instrumentation INNER JOIN (Composer INNER JOIN Pieces ON Composer.ID = Pieces.Composer) ON Instrumentation.ID = Pieces.Instrumentation) ON Location.ID = Pieces.Location) INNER JOIN Location AS Location_1 ON Pieces.Location_2 = Location_1.ID WHERE (((Pieces.ID)=[forms]![Edit Piece].[TitleSelector]));