Solved

Append and Switch?

Posted on 2014-12-07
11
116 Views
Last Modified: 2014-12-22
Experts,

I  have an Append query. I am appending from Excel.  
The table (tblReport) I am Appending to has a field [Receivor] with a property of Number, combo box and a row source query of: SELECT tblReceivor.ID, tblReceivor.Receivor FROM tblReceivor ORDER BY tblReceivor.Receivor;

tblReceivor has 26 records.  

How to Append this text data from Excel [Receivor] to this field tblReport.[Receivor] with a Number ppty?  I know a Switch statement would work however I think SWITCH is more practical for <5 options or so and is not very practical for 26 options to account for.   I imagine there is an easier way.  

thank you
0
Comment
Question by:pdvsa
  • 6
  • 4
11 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40485883
If I've got that many values to define new values for, I usually create a lookup table and just join the Excel file to that table and pull in the value from the lookup table.
0
 

Author Comment

by:pdvsa
ID: 40485903
Hi Dale, could you give me a little more explanation?  I am thinking the lookup table is the table I have now (tblReceivor).  I dont quite get the setup of the Append and the lookup table.  Not certain if you are saying I need to have this lookup table in the Append query.    Thank you

here is my append query if it might make more sense:
INSERT INTO tblReport ( Timing, RequiredAttendee, Label, Deliverable_Or_Notice, Receivor, SectionReferenced, Description, ResponsibleParty, End_Start_Date_Comments, Comments )
SELECT Imported_Excel.Timing, Imported_Excel.[Required Attendee], Imported_Excel.Label, Imported_Excel.Deliverable_Or_Notice, Imported_Excel.Receivor, Imported_Excel.Section_Referenced, Imported_Excel.Description, Imported_Excel.ResponsibleParty, Imported_Excel.End_Start_Date_Comments, Imported_Excel.Comments
FROM Imported_Excel;
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40486020
Where were you thinking of using the Switch( ) function in this SQL?

What did you mean by:
"How to Append this text data from Excel [Receivor] to this field tblReport.[Receivor] with a Number ppty?  "
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:pdvsa
ID: 40486102
The Switch would have been placed on the Receivor field. (Typing from phone).   For example if the record was "bank" in the excel then the number 1 would be put in the field instead of "bank".  Very crude example but I think you know what I mean.  

Not sure if that answers your question.  Let me know
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
ID: 40486289
I think you should first import all receivors by name from Excel to tblReceivor.

Then adjust your append query to inner join between the table of imported reports and tblReceivor on the name of the receivor. Then, from tblReceivor, you would pull the ID, not the receivor name, into tblReports.

/gustav
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 250 total points
ID: 40486506
Sorry, was not sure I understood what tblReceivors was for.

INSERT INTO tblReport ( Timing, RequiredAttendee, Label, Deliverable_Or_Notice, Receivor, SectionReferenced, Description, ResponsibleParty, End_Start_Date_Comments, Comments )
SELECT Imported_Excel.Timing, Imported_Excel.[Required Attendee], Imported_Excel.Label, Imported_Excel.Deliverable_Or_Notice, tblReceivor.ID, Imported_Excel.Section_Referenced, Imported_Excel.Description, Imported_Excel.ResponsibleParty, Imported_Excel.End_Start_Date_Comments, Imported_Excel.Comments
FROM Imported_Excel
LEFT JOIN tblReceivor ON Imported_Excel.Receivor = tblReceivor.Receivor

Because of the LEFT JOIN, any of the Receivor values in the Excel file that are not found in tblReceivor would result in NULLs in the ID field.  So, before actually doing the insert, I would check that field for values not found in tblReceivors.

SELECT DISTINCT Imported_Excel.Receivor
FROM Imported_Excel
LEFT JOIN tblReceivor
ON Imported_Excel.Receivor = tblReceivor.Receivor
WHERE tblReceivor.ID IS NULL

If this returns records, you can display a message indicating the values that are unacceptable and provide the opportunity to fix the Excel file before proceeding, or you could simply perform the import and then provide a way for the user to fill in the NULL values in tblReporting.
0
 

Author Comment

by:pdvsa
ID: 40486584
Thank you Dale.  I think I get it now.  Will test in a bit once get in front of the computer.

Have a good day
0
 

Author Comment

by:pdvsa
ID: 40486599
Hi GUSTAV, I didn't see your response.  

I think you hit the nail on the head.  I have to pull in the ID on tblReceivor.

Not sure if Dale said that in the above tho through code.  

On my way to office.  Will test after awhile...
0
 

Author Comment

by:pdvsa
ID: 40486601
I think Dale is pulling in the ID...I can't read code that well tho... :)
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40486616
Yes, my recommendation would pull in the ID value rather than the Receivor value into tblReports.  As I said, if there are invalid values in your Excel files Receivor column, they would show up as NULL in tblReports.
0
 

Author Closing Comment

by:pdvsa
ID: 40513887
Thank you.  Forgot about this one
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
A Function to parse a text string 4 36
Access query expression 6 20
DCount Type Mismatch 2 22
MS access 2010. Trouble on exporting to excel 2010 13 10
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question