+ Reply to Thread
Results 1 to 10 of 10

Creating a userform that links to a main table plus sub table

  1. #1
    Registered User
    Join Date
    08-18-2020
    Location
    England
    MS-Off Ver
    2007
    Posts
    64

    Creating a userform that links to a main table plus sub table

    Hi,

    I created a spreadsheet previously, that uses VBA to create an invoice in PDF format from the data submitted in an Excel userform. One of the fields in the userform is a drop down list of suppliers (originating from an Access database table), and the address automatically appears in the invoice, based on the selected supplier. Just to clarify, I've linked the spreadsheet to Access, so that the supplier table is also on the spreadsheet itself.

    That all works perfectly. However, it recently transpires that one of the suppliers is prone to have various addresses, even though their company name remains the same. The problem is, if I update the address on the table, the previous invoices stored on the Access database are going to be inaccurate.

    So I'm thinking of creating a sub table in Access (called t_SupplierAddresses or something), whereby suppliers can have more than one address assigned to them.

    So my question is, if I have two tables, the main supplier table and the sub table for the addresses, is it possible for the Excel userform to link to both tables? So that if I select, say, supplier A, all addresses for supplier A appear in another drop down menu, for me to select the correct one from?

    If it is possible, can you explain broadly the approach I should take please? I'm happy to do the research afterwards, I just need a point in the right direction!

    I hope I explained my question clearly, and many thanks in advance.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,975

    Re: Creating a userform that links to a main table plus sub table

    There is no reason why you cannot link to multiple tables: I assume the logic is look in Main table and then check if there any addresses in the sub-table for your selected supplier. Combine these to produce your drop down.

    Is there any merit (from a business perspective) in "tagging" addresses as Main or Subsiduary ?

    So it appears to be a simple import of your new table from Access to Excel with appropriate "lookups".
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    08-18-2020
    Location
    England
    MS-Off Ver
    2007
    Posts
    64
    Many thanks John, that's good to know it's possible. I'm not home now, but I'll have a look into that when I'm back.

    Quote Originally Posted by JohnTopley View Post
    There is no reason why you cannot link to multiple tables: I assume the logic is look in Main table and then check if there any addresses in the sub-table for your selected supplier. Combine these to produce your drop down.

    Is there any merit (from a business perspective) in "tagging" addresses as Main or Subsiduary ?

    So it appears to be a simple import of your new table from Access to Excel with appropriate "lookups".

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Creating a userform that links to a main table plus sub table

    Hello:
    Think of the two sheets you see in the attached workbook as two tables in your Access.

    For that reason, the macro that contains the Userform aims to treat the data as if it were taken from an Access file.

    Since the userform mode is 'False', you can select one sheet or another while the userform is displayed:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by beyond Excel; 10-07-2022 at 12:00 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Creating a userform that links to a main table plus sub table

    And here's a variant that includes having a primary address:
    Attached Files Attached Files
    Last edited by beyond Excel; 10-07-2022 at 09:11 PM.

  6. #6
    Registered User
    Join Date
    08-18-2020
    Location
    England
    MS-Off Ver
    2007
    Posts
    64

    Re: Creating a userform that links to a main table plus sub table

    Quote Originally Posted by beyond Excel View Post
    Hello:
    Think of the two sheets you see in the attached workbook as two tables in your Access.

    For that reason, the macro that contains the Userform aims to treat the data as if it were taken from an Access file.

    Since the userform mode is 'False', you can select one sheet or another while the userform is displayed:

    Please Login or Register  to view this content.
    Hi boyond Excel, I'm very sorry for my slow reply, I was out the house until very late, and only just noticed your post now. That's really great, many thanks for that. I'll have a look through the code now, and see how I can apply it to mine. I'll let you know how I get on, and if I get stuck along the way.

    Thanks again.

  7. #7
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Creating a userform that links to a main table plus sub table

    Go ahead, start and try - that's the only way to learn!

  8. #8
    Registered User
    Join Date
    08-18-2020
    Location
    England
    MS-Off Ver
    2007
    Posts
    64

    Re: Creating a userform that links to a main table plus sub table

    Hi Beyond Excel,

    I'm very slowly working through your code to try and understand how it works. I'm concentrating on the first one so far (the one without the primary address), as I think that's probably simpler.

    On first glance, it looks like you use a different and much better method that what I do, to populate the fields in the userform. I would have entered the location of the data in the RowSource box in the userform properties box. But it looks like you've done it by way of "initialize", is that right?

    I'm also a little bit new to Sql, but I understand it a little. Did you use a bit of Spl in the code?

    The other thing I was confused about, is that you have a variable called Rst, which you listed in the declaration, but didn't declare a variable type as such, is that right? I was wondering what the reason for that is?

    Many thanks for your help. I think once I can fully understand how this works I'll have a better chance of applying it to my spreadsheet!

  9. #9
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Creating a userform that links to a main table plus sub table

    Make sure you read and understand the content of the following website:


  10. #10
    Registered User
    Join Date
    08-18-2020
    Location
    England
    MS-Off Ver
    2007
    Posts
    64

    Re: Creating a userform that links to a main table plus sub table

    Quote Originally Posted by beyond Excel View Post
    Make sure you read and understand the content of the following website:

    Thanks, I'll read that now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Creating a summary table from one main table
    By fmoraye in forum Excel General
    Replies: 2
    Last Post: 12-02-2020, 09:34 PM
  2. prepare a table for print by a main table
    By niksirat2030 in forum Excel General
    Replies: 1
    Last Post: 03-02-2017, 08:38 AM
  3. Pivot Table to include data not in main table.
    By ojsevans in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 03-12-2016, 06:23 AM
  4. Replies: 1
    Last Post: 07-29-2015, 05:19 PM
  5. [SOLVED] Creating Tables from a main table that is updating from an external source.
    By beat in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-15-2013, 09:20 AM
  6. [SOLVED] Filter main table by data contained in related table.
    By Dooey123 in forum Access Tables & Databases
    Replies: 8
    Last Post: 09-08-2012, 08:23 AM
  7. Create a new table from the main table when user press Enter button
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2010, 05:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1