473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Access Relationship help please

This is a very nice site and I'd like to say thank you to the mdoerators and site administrator for maintaining. This is my first post; I hope someone can assist.

I'm working on a database for my wife. I pull reports from a program that defines the headings: SSN, NAME, DOB, PR EPR, Last EPR, SUPER, etc..

The supervisor = SUPER and the SSN = their Social Security Number

When I pull the data, the Super comes out with a Social Security Number. I need to establish a relationship or query that identifies the SSN by their NAME.

I can only download the main data in a set manner, there are no adjustments to the linked table in my database.

Example:

Expand|Select|Wrap|Line Numbers
  1. NAME             SSN         DOB     EPR LAST           SUPER
  2. John Doe     111-11-1111  11/2/77     1/1/07         222-22-2222
  3. Jane Doe     222-22-2222   3/4/70      12/4/06       445-22-1111
  4. Jack Doe     333-11-2442   6/1/81      11/3/05       222-22-2222
In this illustration, you can see that Jane supervises John and Jack. 1) How do I get her name to come up in a query and all the personnel she supervises? 2) In a report, when I have SUPER selected, how can I get it to show the NAme instead of the social security number?

Thanks for the help!

MooseMan
Feb 26 '07 #1
19 2156
MMcCarthy
14,534 Expert Mod 8TB
Hi MooseMan

Hide the SUPER field on the report but don't remove it. Now add a New text box and set the control source to

Expand|Select|Wrap|Line Numbers
  1. =DLookup("[NAME]","Table or Query Name","SSN=" & [SUPER])
  2.  
Mary
Feb 27 '07 #2
Thank you Mary! I'll give it a try.
Feb 27 '07 #3
I tried as suggested but to no avail, I had no luck. Any other suggestions?
Feb 28 '07 #4
Rabbit
12,516 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. =DLookup("[NAME]","Table or Query Name","SSN='" & [SUPER] & "'")
  2.  
Had to modify Mary's code a little. SSN is stored as a text field.
Feb 28 '07 #5
NeoPa
32,556 Expert Mod 16PB
The recommended approach would be to link the table to itself in the source query (that would be another instance of itself). A LEFT JOIN would be required unless you could state categorically that all records have a SUPER value.
What do you currently have as the source of your form?
Feb 28 '07 #6
NeoPa
32,556 Expert Mod 16PB
BTW the other Experts here who posted the DLookup() solutions are both sacked (even though one outranks me of course). She should know better (tsk-tsk).
Feb 28 '07 #7
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. SELECT T1.NAME,T1.SSN,T1.DOB,T1.[EPR LAST],
  2.        T1.SUPER,T2.Name AS SUPERNAME
  3. FROM YourTable AS T1 LEFT JOIN YourTable AS T2
  4.   ON T1.SUPER=T2.SSN
Is the sort of thing you need. I don't know your table name so I improvised but I'm sure you get the idea. Using DLookup is actually something you can get away with in most cases, it just gets slower very quickly as the number of records to process increases (They know I'm just kidding). Not recommended as good design though.
Feb 28 '07 #8
The recommended approach would be to link the table to itself in the source query (that would be another instance of itself). A LEFT JOIN would be required unless you could state categorically that all records have a SUPER value.
What do you currently have as the source of your form?
Main Data Query is the source
Mar 1 '07 #9
NeoPa
32,556 Expert Mod 16PB
Main Data Query is the source
And ... ?
Mar 1 '07 #10
ADezii
8,834 Expert 8TB
This is a very nice site and I'd like to say thank you to the mdoerators and site administrator for maintaining. This is my first post; I hope someone can assist.

I'm working on a database for my wife. I pull reports from a program that defines the headings: SSN, NAME, DOB, PR EPR, Last EPR, SUPER, etc..

The supervisor = SUPER and the SSN = their Social Security Number

When I pull the data, the Super comes out with a Social Security Number. I need to establish a relationship or query that identifies the SSN by their NAME.

I can only download the main data in a set manner, there are no adjustments to the linked table in my database.

Example:

Expand|Select|Wrap|Line Numbers
  1. NAME             SSN         DOB     EPR LAST           SUPER
  2. John Doe     111-11-1111  11/2/77     1/1/07         222-22-2222
  3. Jane Doe     222-22-2222   3/4/70      12/4/06       445-22-1111
  4. Jack Doe     333-11-2442   6/1/81      11/3/05       222-22-2222
In this illustration, you can see that Jane supervises John and Jack. 1) How do I get her name to come up in a query and all the personnel she supervises? 2) In a report, when I have SUPER selected, how can I get it to show the NAme instead of the social security number?

Thanks for the help!

MooseMan
The easiest solution would be a variation of an Auto Join. Create a Query, then enter your Table in it twice. If your Table is named Table1, then entering it into the Query Grid again would produce Table1_2. Create a Join between the SSN Field of Table1 to the Super Field of Table1_2 (Table1.[SSN] ==> Table1_2.[SUPER]. Add any other Fields as required. Make this the Record Source for your Report, then set Hide Duplicates to Yes on the Name Field if so desired.
Mar 1 '07 #11
Okay,

I tried as suggested and the code did not list the name in place of the SSN, instead it lists error#.

Here is how the DB is set up...

Tables: DOWNLOAD (Link table) and MAIN DATA. DOWNLOAD is the excel spreadsheet that has all the main information in it. I loaded that into MAIN DATA table so I can add additional fields. I did this because I can only download the DOWNLOAD sheet. How can I set up a feature that appends information to the MAIN DATA sheet when I update the DOWNLOAD linked table?

I have one query set up right now, Main Data Query. It pulls from MAIN DATA.

In the MAIN DATA, SUPER field is formated in this way: Number, 000-00-0000, and NAME field as text, 255

I really appreciate your help on this.
Mar 1 '07 #12
NeoPa
32,556 Expert Mod 16PB
Main Data Query is the source
And ... ?
Sorry to sound short with you, but I need to know more precisely what the name is ([Main Data]; [Main Data Query]) and I need to know what more you would like me to help with.
Mar 1 '07 #13
NeoPa
32,556 Expert Mod 16PB
Okay,

I tried as suggested and the code did not list the name in place of the SSN, instead it lists error#.

Here is how the DB is set up...

Tables: DOWNLOAD (Link table) and MAIN DATA. DOWNLOAD is the excel spreadsheet that has all the main information in it. I loaded that into MAIN DATA table so I can add additional fields. I did this because I can only download the DOWNLOAD sheet. How can I set up a feature that appends information to the MAIN DATA sheet when I update the DOWNLOAD linked table?

I have one query set up right now, Main Data Query. It pulls from MAIN DATA.

In the MAIN DATA, SUPER field is formated in this way: Number, 000-00-0000, and NAME field as text, 255

I really appreciate your help on this.
I missed this earlier as I had loaded the page a while back.
I try to fit these in at work when I get a short break so I may have a number open for a while just waiting.
I'll read through this now and try to come back to you on it shortly.
Mar 1 '07 #14
NeoPa
32,556 Expert Mod 16PB
How can I set up a feature that appends information to the MAIN DATA sheet when I update the DOWNLOAD linked table?
I don't understand this question :(
I have one query set up right now, Main Data Query. It pulls from MAIN DATA.

In the MAIN DATA, SUPER field is formated in this way: Number, 000-00-0000, and NAME field as text, 255
Is the data you showed in the original post from the [Main Data Query] or is it from [MAIN DATA]?
Can you post the SQL of [Main Data Query] so we can understand better what's going on.
Mar 1 '07 #15
Expand|Select|Wrap|Line Numbers
  1. SELECT [Main Data].SSAN,
  2.        [Main Data].RANK,
  3.        [Main Data].SUPER,
  4.        [Main Data].NAME,
  5.        [Main Data].[OFF SYM],
  6.        [Main Data].[Type Award],
  7.        [Main Data].[Date DECOR Received],
  8.        [Main Data].[Date DECOR to 9RW],
  9.        [Main Data].[Date DECOR RTD for Correction],
  10.        [Main Data].[Date DECOR to MPF],
  11.        [Main Data].[Date RIP DECOR  received and sent],
  12.        [Main Data].[Date DECOR due to SGS],
  13.        [Main Data].[DECOR Susp to MPF]
  14. FROM [Main Data] INNER JOIN [Main Data] AS [Main Data_1]
  15.   ON [Main Data].SUPER = [Main Data_1].SSAN
  16. WHERE ((([Main Data].SUPER)=
  17.          DLookUp("[NAME]",
  18.                  "Main Data",
  19.                  "SSAN='" & [SUPER] & "'")
The original post is from Main Data
Mar 1 '07 #16
NeoPa
32,556 Expert Mod 16PB
I'm not sure exactly where we are atm but I'm sure the SQL you've posted doesn't work (After displaying it visibly).
Firstly, the parentheses in your WHERE clause are not balanced.
Sendly, the whole WHERE clause is nonsense (sorry to be stark about it).

The good news is that you can just drop it completely. The SQL up to that point is perfect (As far as I know from what I do know of your data).
Mar 1 '07 #17
NeoPa
32,556 Expert Mod 16PB
...Except that while you've linked perfectly to the matching record of the SUPER you haven't actually selected any field from that record to show.
An extra line should do the trick, in the SELECT clause :
Expand|Select|Wrap|Line Numbers
  1. [Main Data_1].NAME AS SuperName,
Leaving SQL for your [Main Data Query] of :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Main Data].SSAN,
  2.        [Main Data].RANK,
  3.        [Main Data].SUPER,
  4.        [Main Data].NAME,
  5.        [Main Data_1].NAME AS SuperName,
  6.        [Main Data].[OFF SYM],
  7.        [Main Data].[Type Award],
  8.        [Main Data].[Date DECOR Received],
  9.        [Main Data].[Date DECOR to 9RW],
  10.        [Main Data].[Date DECOR RTD for Correction],
  11.        [Main Data].[Date DECOR to MPF],
  12.        [Main Data].[Date RIP DECOR  received and sent],
  13.        [Main Data].[Date DECOR due to SGS],
  14.        [Main Data].[DECOR Susp to MPF]
  15. FROM [Main Data] INNER JOIN [Main Data] AS [Main Data_1]
  16.   ON [Main Data].SUPER = [Main Data_1].SSAN
Mar 1 '07 #18
That worked perfectly; thank you very much.

On another note: How can I set MAIN DATA Table to update automatically with the DOWNLOAD (linked excel sheet) table?
Mar 2 '07 #19
NeoPa
32,556 Expert Mod 16PB
Not a problem. I'm pleased that helped.

On the other note, You should post this as a new thread as it's not really connected with the question asked in this one.
I expect you'll need to phrase it more clearly though, explaining exactly what you need help with.
Mar 2 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Fred | last post by:
Hi. How do I import while mapping an excel table to an access table please??? I've searched around and all I can find is a software product or code that does the same thing as the access...
4
by: JSMiami | last post by:
I have a form that is fed by a certain table. This table connects to an intermeddiate table and then a look up table. All of this is done to accomplish a many-to-many relationship. Imagine that the...
3
by: Leinad Kong | last post by:
I'm using Access 2002, as front-end and back-end as well: 1) I faced database corrupted problems, when more than 1 user edit concurrently. I'm using All-records Locking, and open-exclusively as...
9
by: Alan Lane | last post by:
Hello world: Background: Yesterday, January 21, Doug Steele was kind enough to help me out on a Left Join problem. I was trying to return all stores and their Gross Adds for December, 2004...
2
by: Cary | last post by:
This may reveal my poor programming skills, but here goes... I'm building a pricing tool for my business. I'm nearing the end of the project, and I've been asked to be able to save quotes in some...
33
by: Steve | last post by:
One of our clients recently upgraded their Office version to 2003. When they tried to run our program (written in Access 2000), they ended up with the wrong data. My coworker and I have tested this...
12
by: Selva Chinnasamy | last post by:
Hi I am using batch commands against Ms-Access and getting an error Message "Characters found after end of SQL statement." String Here is my sql Dim str_screens As String = "Select * from Screens...
4
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database...
10
by: Richard | last post by:
Hi folks, thanks for taking the time to read this (and hopefully point our where I'm going wrong). The scenario: I have a local Access2007 database which links in several read only mySql...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.