Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    PrimaryKey is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2018
    Posts
    42

    Passing varible from mainform to popup subform - and then passing new variables back. Possible?

    I have a somewhat complicated question (at least in my mind) for all of you Access gurus.



    I’m working on developing an Order form that (for the purposes of this question) involves three tables:

    • Orders
    • Customers
    • cust_CustomerAddresses


    The main Orders form is linked to the sales_Orders table, and there’s a dropdown box on the form where you select the Customer to attach to the order. That dropdown box is linked to the CustomerID field in the Orders table, and populates with Customer names when selected.

    After a user has selected a customer, they then need to select the Billing and Shipping address for the Customer. Since some Customers have multiple addresses for their various facilities, a single Customer record might have two or three different Billing/Shipping addresses, so automatically updating a pre-built Billing/Shipping addresses subform isn’t an option – instead the user will need to select an address. I figured I wouldn’t use a subform that’s embedded in the main form, instead I’d just use a popup to select the address and have that popup send the AddressID and street/city/state info back to the mainform. Only the AddressID is stored in the sales_Orders table for the Order record, the street/city/state/zip is just shown to the user for reference/confirmation purposes.

    I’ve given it a lot of thought, and here’s what I came up with so far:

    Once a Customer is selected, two buttons appear in the addresses section on the main Orders form - basically a “Select Address” button beneath both the Billing Address section and the Shipping Address section. When clicked I want this button to launch a popup subform where the user can browse through the addresses on file for the selected customer, and then press a “Select” button once they’ve found the record they want to use for the billing and shipping address, which will then pass the AddressID back to the Orders form along with the address details. Once an address has been selected (and as long as the Customer selection doesn’t change), I want the “Select Address” button to change to “Edit Address.”

    I figured I could use OpenArgs to pass the CustomerID of the customer selected via the dropdown box to the popup Customer Address subform when the Select Address button is clicked. There, that ID would be used to filter the available addresses to show only those records where the CustomerID is a match. What I don’t know how to do is pass the AddressID of the selected address back to the Orders form, since the Orders form is already open, and my only experience using OpenArgs applies to cases where I’m opening a new form and passing a variable to it.

    Also, I wanted to make such that if the Customer Selection changed on the Orders form and a new customer was selected, then the selected Addresses were cleared – but only if a new Customer was selected. If a user used the Customer dropdown and selected the same Customer, I’d want the addresses to stay put, but if they selected a different customer I want them to clear and the buttons to revert from “Edit Address” to “Select Address”.

    Finally – I’d like users to be able to add new addresses to the Customer record if the address they need isn’t yet attached to the customer record. I assume that will be pretty straightforward since the record source for the popup form will be the cust_CustomerAddresses table, but since I passed the CustomerID to the subform programmatically I wanted to be sure I’d still be able to add new addresses using this method.

    So, my questions are:
    1. - I know how to pass the CustomerID from the Orders form to the popup CustomerAddress subform, but how do I pass the AddressID of the selected address back to the already-open Orders form, and populate some textboxes with that addresses information (street, city, state, zip, etc.)?

    2. - I can imagine how to write an event that would clear the customer address selection fields if the Customer Selection dropdown box was used to select a different customer by comparing the CusotmerId of that already-selected customer to the CustomerID of the newly selected customer, but how would I get the CustomerId of the customer that’s already selected if I’m attaching the event to the AfterUpdate property of the combobox? Should I use “Before Update” instead?

    3. - Will users still be able to add new addresses in the popup Customer Address subform, just like a normal subform, even though I passed the CustomerID to the form via VBA? Should I store the CustomerID in an invisible textfield and use that? Also – will the standard “New Record” command button macros work in that subform?

    I’m really sorry for all of the questions – this is probably the most complex thing I’ve ever tried to do with Access and I just wanted to run it past you all before building it only to find it won’t/can’t work. You guys have been so helpful and knowledgeable that I feel like I’ve learned more reading these forums the last few weeks than years of building simple Access databases.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  3. #3
    PrimaryKey is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2018
    Posts
    42
    Quote Originally Posted by orange View Post
    Here is a link to deal with adding a new record to a list.
    Can you post your tables and relationships as a jpg?

    Thank you for your reply. Sure - I'm out of town today for my niece's first birthday, but when I get back I can. If you have any questions about specific tables/relationships in the mean time I'd be happy to answer until I can get back in my from of my workstation.


    Thank you for the link. Were you suggesting I use that means of allowing users to select an address as opposed the method I had proposed, or was this something that would help me build the popup form means of doing it? I had thought about populating an addresses combo box on the Orders main form based on the customer selector, the only problem is the amount of information that would need to be shown in each combo box in order for a user to confirm they're selecting the right address.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    It is your application, so whether or not a user should be adding entries that do not exist already is a business decision at your end.
    I was only showing a technique to add an entry to a list (better method than older ways).
    I recommend developers get their business rules clearly defined; build a data model; use some test data to vet the model; then build the database.
    Forms and subforms etc come after basic database design, in my view.

    Good luck with your project.

  5. #5
    PrimaryKey is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2018
    Posts
    42
    Orange - thank you for getting back to me. I completely agree with you. We had a series of meetings before beginning work that defined the business requirements which I then translated into the functional requirements of the database. I usually build in MySQL/PHP, so I'm typically building DFD diagrams, ERD diagrams, etc., in Visio, but was told not to bother when building in Access since access displays those relationships as well.

    Anyway, yah - it'd be highly beneficial if users could add new address records when building out an order. I just don't know how to pass data from a popup form back to a main form that's already open. And I don't know how to check the CustomerID that's in a combo box both before and after a user interacts with the combobox to determine if they changed the CustomerID (in order to clear the selected addresses). I don't know why a user would ever click the customer selection dropdown and pick the same customer that was already selected, but still thought it best to prevent that action from wiping out the addresses.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I usually build in MySQL/PHP, so I'm typically building DFD diagrams, ERD diagrams, etc., in Visio, but was told not to bother when building in Access since access displays those relationships as well.
    Not so-Access won't show the relationships unless you identify them. You know from experience you do your analysis and design. If you use DFD and ERD in your approach, I see no reason to drop proven practices just because it's Access. But, many using Access have evolved from spreadsheets (not all, but many) and treat Access as a big brother of Excel. Totally wrong- but that's what I see. Many new user/developers of Access do not know nor appreciate business rules, analysis, design, prototyping, DFD, ERD,test scenarios... (or stump the model). And M$oft marketing hasn't helped that situation --but they do sell more product. User/developers then have to learn database, analysis.....

    If you watch the video I mentioned previously, you'll see that the approach suggested should work.

    Good luck.

  7. #7
    PrimaryKey is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2018
    Posts
    42
    Thanks again for getting back to me. I agree that documentation is vital to the success of any system design. I did do considerable documentation/diagramming related to I/O requirements and process - but I kept all the ERD in the Access Relationships window. It leaves something to be desired for someone used to working in Visio, though I admit it's a lot quicker if you want to exhaustively list your fields.

    I watched the video a couple of times - and the creator demonstrates adding a record with a single field. My edit-list form would have multiple fields (Alias, Street, Street2, City, State, Zip, Country, Notes). I don't necessarily see any problem there as I could build the popup form include those fields, but it wasn't made clear in the video if this feature passes the CustomerID to the popup form, especially if I'm populating the combo box list of Addresses using VBA, which is what I'd have to do since the main form is linked to the Orders table, not the Customers table. I considered designing it the other way around, with the Customer form as the main form and the Orders form being a subform, but this created other problems that were more difficult to address than doing it this way - plus with that method the record navigation would go through customer records, as opposed to order records.

    So basically when a user selects a customer from the customer selection dropdown, I would have an after-update event that populates the address selection dropdown for both the billing and shipping address combo box (assuming I go that route). Would this technique still function properly using that method, do you think?

    The other issue is populating the combo box with addresses. The user would need to see the address type, alias, street, street2, city, state, and zip for each address in the combo box. I know how to force a newline in a message box, but I don't think you can do that with a combo box, so all that info would be on one very long line in the address combo box. Is there a way to have combo box entries be multi-line to make the information more digestible?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    No, comboboxes cannot be multi-line.

    The tutorial provides a method for updating a lookup table. These lookup records are not usually associated with a specific data record, such as a list of customers. Each customer could be associated with any order record. You want a table of addresses where each address record is associated with a single customer. Passing the customer ID to the popup form can be done several ways. One I often use is the OpenArgs argument of OpenForm.

    DoCmd.OpenForm "formname", , , , acFormAdd, acDialog, Me.cbxCust
    Me.cbxCust.Requery

    Code behind the popup form would read its OpenArgs property and populate new record, something like:

    If Not IsNull(Me.OpenArgs) Then Me.tbxCustID_FK = Me.OpenArgs

    Alternative approaches could involve dependent listbox or subform to display address records associated with selected customer.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    PrimaryKey is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2018
    Posts
    42
    Quote Originally Posted by June7 View Post
    No, comboboxes cannot be multi-line.

    The tutorial provides a method for updating a lookup table. These lookup records are not usually associated with a specific data record, such as a list of customers. Each customer could be associated with any order record. You want a table of addresses where each address record is associated with a single customer. Passing the customer ID to the popup form can be done several ways. One I often use is the OpenArgs argument of OpenForm.

    DoCmd.OpenForm "formname", , , , acFormAdd, acDialog, Me.cbxCust
    Me.cbxCust.Requery

    Code behind the popup form would read its OpenArgs property and populate new record, something like:

    If Not IsNull(Me.OpenArgs) Then Me.tbxCustID_FK = Me.OpenArgs

    Alternative approaches could involve dependent listbox or subform to display address records associated with selected customer.
    June7 - thank you! That's how I planned on opening the popup subform and passing the CustID to it from the Orders form. On that form the user would select Address record, and I need to pass the Address ID, Street, City, State, and Zip back to the Orders form, which is still open (so I can't use OpenForm). Any idea how to do that?

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Seems you have these tables (and possibly others)
    Customer, CustomerAddress, AddressType, Order, OrderDetail and Product

    You would normally have forms/subforms to add data to tables. There may be other forms to handle specific business processes. It would probably be one of the table data-entry forms that you would open and add the new record to. The specific form depends on which cbobox is involved(the one dealing with the missing record).

    I just saw you last post after I submitted this one, so am opening it to make an edit/update.


    I need to pass the Address ID, Street, City, State, and Zip back to the Orders form
    You need that new info into the proper table, then query(s) will bring related data back to the form control(s).

    Here is a link to a generic Customer-Order-Product data model from Barry Williams' site. It shows a number of reference tables
    (eg AddressType)

    PS: You may get some ideas from this post. -- I'm linking to page 4, because that's where he asks (and answers) about adding a record to a list.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What do you mean by "can't use OpenForm"? OpenForm is to open the popup, not the Orders form.

    Several methods to 'pass' data between forms: global variable, TempVars (I've never used), set value of control.

    I couldn't view the YouTube so don't know what method it uses to add new record. Here is a tutorial that describes opening a form for input http://www.blueclaw-db.com/access_no...ed_example.htm. It handles populating combobox with new record info.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    PrimaryKey is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2018
    Posts
    42
    Quote Originally Posted by orange View Post
    Seems you have these tables (and possibly others)
    Customer, CustomerAddress, AddressType, Order, OrderDetail and Product
    You would normally have forms/subforms to add data to tables. There may be other forms to handle specific business processes. It would probably be one of the table data-entry forms that you would open and add the new record to. The specific form depends on which cbobox is involved(the one dealing with the missing record).
    Thank you again orange for the reply - your help is very much appreciated.

    You're dead-on - those are indeed the tables that I have. Verbatim, actually - wow. Well done there.

    And yes - typically I am using forms/subforms for this type of thing. The problem with using subforms on the Orders form is that the subforms are linked to anything since the control source of the main form is Orders, not Customers. I am using a subform for the customer selection that linked the CustomerID in the Orders table to the ID in the Customers table, but for address selection (for example) I can't, at least as far as I know, because there's no way for me to use the selection in the subform (such as and AddressID for an address) to populate the AddressID on the Orders form. I could display the records, but I don't know how I'd pass the ID of the selected address record back to the Orders form using this method. If you have any ideas there I'd love to hear them. I'd love to keep it as simple as possible.


    Quote Originally Posted by orange View Post
    Seems you have these tables (and possibly others)
    You need that new info into the proper table, then query(s) will bring related data back to the form control(s).

    Here is a link to a generic Customer-Order-Product data model from Barry Williams' site. It shows a number of reference tables
    (eg AddressType)

    PS: You may get some ideas from this post. -- I'm linking to page 4, because that's where he asks (and answers) about adding a record to a list.
    I will take a look at the model ASAP. Would it also be possible for you elaborate a bit when you say "You need that new info into the proper table, then query(s) will bring related data back to the form control(s)."? My current plan is to have the user select the Address in a popup, but only send the AddressID back to the main form. It'd also send the street/street2/city/state/zip, but only for visual purposes. Only the AddressID would be attached to the Order record. I could store it in a hidden textbox and just display the actual address itself to users. I'd do this for both the billing and shipping addresses.

    Let me take a look at those links. References/examples have been very helpful lately, so I really, really appreciate you taking the time to help me understand this.

    Quote Originally Posted by June7 View Post
    What do you mean by "can't use OpenForm"? OpenForm is to open the popup, not the Orders form.
    Thank you for the reply. So, there are two passes taking place. The user begins on the Orders form, and when the click "Select Address", a popup subform appears that shows all teh address records for that customer. My plan was to use OpenArgs to pass the ID of the selected customer to the popup form to use in the SELECT statement as a constraint. On the popup subform the user can navigate through the address records, and when they find the address they want to use (as many customers are businesses and have 2-5 shipping and billing addresses for their different locations) then click "Ok". And then I have to send the ID of the selected address back to the Orders form. Usually I'd use OpenArgs, but I believe that's only used when opening a new form, not when closing a popup and returning to an already opened form, so I wasn't sure how to do this. You did give me an idea though, I could use Set Value to set the value of the AddressID, and list the selected address details (for reference only).

    If you have other ideas let me know. I'll take a look at your link now too.

  13. #13
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Further to info so far, Dr. Verschuuten has a number of videos on youtube.
    Here's one on Access tabbed forms.

    If you watch a few youtube videos on various aspects of Access (forms/queries etc) I'm sure you'll see some concepts and approaches you have probably used with other software.
    Since you familiar with DFD and logic flow, you could work through the steps involved in what the form and its controls must do to support the business process of adding/modifying an Order or Address. Once you know what must be done, you can try to achieve same and/or ask focused questions on the forum.

  14. #14
    PrimaryKey is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2018
    Posts
    42
    Quote Originally Posted by orange View Post
    Further to info so far, Dr. Verschuuten has a number of videos on youtube.
    Here's one on Access tabbed forms.

    If you watch a few youtube videos on various aspects of Access (forms/queries etc) I'm sure you'll see some concepts and approaches you have probably used with other software.
    Since you familiar with DFD and logic flow, you could work through the steps involved in what the form and its controls must do to support the business process of adding/modifying an Order or Address. Once you know what must be done, you can try to achieve same and/or ask focused questions on the forum.
    Good find. Those are the videos I had watched prior to starting on this database! I watched all his videos on tabbed forms, which is what gave me the idea to build my form as a tabbed form! Very cool.

    The big difference is that in most of his videos the mainform is the one and the subform the many. For various reasons my Order form reverses this, which is making a bit more difficult to work out these last few details.

    At this point I tihnk I have everything I need in order to proceed in terms of understanding what features the database, and Orders form in particular, needs to support in order to meet the system's functional requirements. Just need to find a way to pass data from mainform > popup subform > mainform. Alternatively I could use dynamically populated combo-boxes, it's just that with that method I lose the ability to allow users to edit the addresses. Still hoping I can come up with a way to just pass the data.

    I still need to check out that example database you sent (don't have Access on this machine) - thank you again for that. Much appreciated.

  15. #15
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    The big difference is that in most of his videos the mainform is the one and the subform the many
    That's the typical setup with Form/subform -- the 1 side is the form and the many goes on the subform.
    Examples:
    A student takes many courses.
    A Person has many Hobbies.
    A Customer has many Orders.
    An Order has many lineItems.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Passing global variables question
    By newbieX in forum Programming
    Replies: 6
    Last Post: 10-03-2014, 02:09 PM
  2. Replies: 6
    Last Post: 07-16-2014, 12:18 PM
  3. Passing Variables creates more problems
    By dccjr in forum Programming
    Replies: 2
    Last Post: 04-05-2013, 06:40 AM
  4. Passing a variable back from a sub
    By RonL in forum Programming
    Replies: 7
    Last Post: 01-25-2013, 12:10 AM
  5. Passing variables to a Word Doc.
    By techexpressinc in forum Forms
    Replies: 2
    Last Post: 09-16-2010, 01:04 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