Results 1 to 8 of 8
  1. #1
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24

    Displaying Multiple Relationships

    Hello All,



    I'm relatively new to Access so please excuse me if this is an ignorant question. I searched via Google and on this forum for the answer to this but I have yet to come across a solution.

    I have a simple database with 2 tables. Table one lists asset information ("Assets"), table two lists contact information ("Contacts"). The relationship between the two tables is one-to-many, in the sense that, every Assets is owned by one company while each company has a few entries in the Contacts Database.

    I have a report which lists each company in Alphabetical order and below shows the properties owned by that company. I want to also show EVERY contact for the company within the "Company" header. I've been successful at showing the contact information for ONE contact within the report, as it is a simple query; however, I would truly like to show all of the contacts associated with each company. Does anyone have any initial thoughts as to how one might go about this.

    Thanks in advance,
    Paddon

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    have you thought about querying the results out with an inner join and producing a report off of that? you might also be able to produce the layers in a vertical fashion by using the report wizard and using the query as the source. I think the wizard still produces formats like that.

  3. #3
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    I tried a number of things within the report wizard and didn't have any success. The biggest issue was that I would always get duplicates of the Asset information making the report gigantic. For example:

    Company A

    Property 1 - Person One
    Property 1 - Person Two
    Property 1 - Person Three
    etc...

    It seemed to do this no matter which iteration of grouping that I tried.

    Forgive me but I am uneducated as to how to implement an inner join query in access on just one table. Could you elaborate on the procedure?

    Thanks!

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you can't join one table, paddon, hence the meaning of the word "join". Only works with 2 or more tables.

    So, what do you want your report to look like anyway? some like:

    Code:
    Field1	Field2
    asset1	
    	prop1
    	prop2
    	prop3
    asset2	prop1
    	prop2
    asset3	
    	prop1
    	prop2
    	prop3
    is that kind of the structure you want it to look like?

  5. #5
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    ajetrumpet - thank you for your help so far. Hopefully I can clarify a little better below.

    Oops, Asset = Property, I just switch out the two terms inadvertently.

    "Asset" Information is in a table like:

    Code:
     | Data1 | Data2 |Data 3 | Company
    Asset1 |    |    |    |     
    Asset2 |    |    |    |     
    Asset3 |    |    |    |     
    Asset4 |    |    |    |
    "Contact" information is a table such as:

    Code:
     | Phone| Email | Address | Company
    Contact1 |    |    |    |     
    Contact2 |    |    |    |     
    Contact3 |    |    |    |     
    Contact4 |    |    |    |
    As you can see the relationship that relates the Asset table to the Contacts table is the "Company" field.

    I'd like the report too look like this:

    Code:
     |   |   |   |
    Company 1 | Contact1 | Contact2 |Contact3
        | Asset1 | Asset1.Data1 | Asset1.Data2 | Asset1.Data3 |
        | Asset2 | Asset2.Data1 | Asset2.Data2 | Asset2.Data3 |
    Company 2 | Contact | Contact |Contact 
        | Asset3 | Asset3.Data1 | Asset3.Data2 | Asset3.Data3
    Where Contact1... Contactn are all of the contacts I have for each Company.

    Thank you,
    Paddon

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    well, without testing this in my own db, I can tell you that most likely you're going to have to run a crosstab query to get the data to display in that fashion, at the very least.

    The wizard will not do that. Have you considered an export over to Excel? Excel is much more flexible with formats like this, and you can essentially make Excel sheets look identical to Access reports with simple formatting. And for printing purposes, it comes out exactly the same anyway, so if you are printing these outputs, the program in which you produce it really doesn't matter, unless the boss keeps you from doing it the quickest way possible.

    Bottom line, this is much easier to produce in excel. but, that's from my persective only. an expert of crosstabs would be able to give you more information, but I've been posting on forums long enough to know that not many people post a lot on crosstabs. They're not really used that much in Access, assuming. Plus, many do not have much experience with them, as I am kind of in that same boat (I only use them for finance reports).

  7. #7
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    I would do it in excel if there weren't so many entries. It isn't time effective to do so unfortunately. Is there an expression I can write that may accomplish this?

    For example, so far I run a query that just selects all the information I want contained in my report about the property and includes a field with formatted contact data. Therefore the query contains columns with Data1, Data2, Data3, Company and "Expr1".

    Expr1 is just contact information formatted to display in one field. i.e.)

    Expr1: [Name] & Chr(13) & Chr(10) & [Company] & Chr(13) & Chr(10) & "(p): " & [Phone] & Chr(13) & Chr(10) & "(e): " & [Email]
    So the Query looks like this

    Code:
     Asset Name | Data 1 | Data 2 | Data 3 | Company | Expr1
    Asset 1  |  5555    |  6666  |  6666  |  ABC Inc  | John Doe, ABC Inc, (555) 555 5555, jdoe@abcinc.com
    I then generate the report from this query and I get a report exactly like this:

    [table="head;width=750px"] | | | |
    Company 1 | Contact | |
    | Asset1 | Asset1.Data1 | Asset1.Data2 | Asset1.Data3 |
    | Asset2 | Asset2.Data1 | Asset2.Data2 | Asset2.Data3 |
    Company 2 | Contact | |
    | Asset3 | Asset3.Data1 | Asset3.Data2 | Asset3.Data3
    [/CODE]

    Where “Contact” is merely one contact from that company (the first one).
    Do you think there is there a way to modify the above expression, call it Expr2 such that it selects the next entry that has the same [Company] field? Then my query from which I build the report would look more like:

    Code:
     Asset Name | Data 1 | Data 2 | Data 3 | Company | Expr1 | Exp2 
    Asset 1  |  5555    |  6666  |  6666  |  ABC Inc  | John Doe, ABC Inc, (555) 555 5555, jdoe@abinc.com   | Jane Doe, ABC Inc, (555) 555 5555, janedoe@abcinc.com

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Yes you can do that, Paddon. But the thing that many people miss about doing this sort of thing is that it has to be done with recordsets via VBA code because the query wizard cannot manipulate data like that.

    what you can do is loop your table, after sorting the records (if need be) and check the records via some condition and/or some conditional field after every record is processed to determine if it should be concatenated into a new record line (new LINE in the field, NOT record), as you've shown in your last table example. consider a table like this, called OLDTABLE:

    Code:
    CONTACT	COMPANY	notes
    adam	company a	dummy field
    bob	company a	dummy field
    jay	company b	dummy field
    ron	company b	dummy field
    brett	company c	dummy field
    If I want to produce an output like what you've shown you want, I would write this kind of procedure:
    Code:
    sub newoutput
    
    On Error Resume Next
    
    dim c as string
    dim sContacts as string
    dim sNotes as string
    Dim tbl As DAO.TableDef
    dim rs as dao.recordset
    dim rs2 as dao.recordset
    Dim f As field
    Dim db As DAO.Database
    Set db = CurrentDb
    
       Set tbl = db.CreateTableDef("companyinfo")
         With tbl
                   .Fields.Append .CreateField("company", dbtext, 255)
                   .Fields.Append .CreateField("contacts", dbmemo)
                   .Fields.Append .CreateField("contactnotes", dbmemo)
         End With
           db.TableDefs.Append tbl
    
    set rs = db.openrecordset("companyinfo")
    set rs2 = db.openrecordset("SELECT * FROM oldtable " & _
                                  "ORDER BY company, contact")
    
    with rs2
       .movelast
       .movefirst
    
       c = !company
    
          do until .eof
             while !company = c and not .eof
                sContacts = sContacts & !contact & vbcrlf
                sNotes = sNotes & !contact & " - " & !notes & vbcrlf
                   .movenext
             wend
    
                rs.addnew
                rs!company = c
                rs!contacts = sContacts
                rs!contactnotes = sNotes
                rs.update
    
                   c = !company
          loop
    end with
    
    rs.close
    rs2.close
    db.close
    
    set rs = nothing
    set rs2 = nothing
    set db = nothing
    set tbl = nothing
    
    end sub
    And after all of that, you would get a new table that looks like this (I used the table tags here. The records with blank "company" field would be new lines in the actual company record. so, 3 records total for this example output):


    Code:
    COMPANY	CONTACTS	NOTES
    company a	adam	adam - dummy field
    	bob	bob - dummy field
    company b	jay	jay - dummy field
    	ron	ron - dummy field
    company c	brett	brett - dummy field
    Does that make sense? You can do the same thing with your assets. I'm not sure there is any other easy way to do it, because Access does not compliment this kind of manipulation at all. I've already said that though.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Relationships again
    By BarbT in forum Access
    Replies: 2
    Last Post: 11-09-2010, 04:12 AM
  2. One to many relationships
    By CoachBarker in forum Database Design
    Replies: 1
    Last Post: 09-13-2010, 09:01 PM
  3. Too Many Relationships
    By MikeT in forum Database Design
    Replies: 4
    Last Post: 08-25-2010, 07:23 PM
  4. Reports relationships
    By nashr1928 in forum Reports
    Replies: 1
    Last Post: 07-14-2010, 08:01 PM
  5. Relationships?
    By rosh41 in forum Database Design
    Replies: 2
    Last Post: 06-23-2010, 01:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums