Results 1 to 13 of 13
  1. #1
    Thomasso is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250

    Using the same form with different record sources based on button clicked

    Hello everybody.



    I have a database where I store customer orders and supplier orders at the same time. These orders are very similar so the form can look the same. I have these forms:
    • orders overview
    • order card
    • order details subform
    • data entry forms


    There are buttons for adding a new order, editing an order, navigation etc.

    In the main menu, there are buttons: CUSTOMER ORDERS and SUPPLIER ORDERS. I want to set record sources for all those forms based on the button an user clicked on in the main menu. How do I approach this?

    I also need specific objects to have their default value set based on the button.

    One solution would be to create duplicate forms but I have a feeling that there is a more elegant way.

    Thanks,
    Tomas

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    you haven't said how your form works - so assuming they choose which type of order on the button, I assume they then select a customer or a supplier as appropriate in a combo box. you presumably have a table for customer/supplier details which will include a flag to indicate which type they are, so set the rowsource to include a criteria based on this flag.

    behind the customer button, so code would be something like (change names/types to suit)

    me.cboChoose.rowsource="SELECT EntityID, EntityName From tblCustSupps WHERE EntityType='customer'"

    and behind the supplier

    me.cboChoose.rowsource="SELECT EntityID, EntityName From tblCustSupps WHERE EntityType='Supplier'"

    Or perhaps if your entity type is a number you could use an option group rather than buttons

  3. #3
    Thomasso is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Sorry, should have been more clear. The forms work like this:

    Click image for larger version. 

Name:	form10.PNG 
Views:	26 
Size:	42.0 KB 
ID:	27474
    This is the orders overview form, I have 2 queries, one shows supplier orders, the other customer orders. I want to set one of the queries as the record source for this form (based on the button).

    In addition, I want to change the label in the header and a caption of the second button.

    Click image for larger version. 

Name:	form11.PNG 
Views:	24 
Size:	33.0 KB 
ID:	27475
    When I click the button on the left (next to an order), this form appears. It's the Order Details form. I don't think this needs to be modified. The button at the top says "edit information".

    Click image for larger version. 

Name:	form12.PNG 
Views:	24 
Size:	18.1 KB 
ID:	27476
    This is my data entry form, it is accessed via the orders overview form by clicking on Add a new order button or clicking on Edit information button in the details form. I need the row source of the yellow combo box to be either a list of all the customers or the suppliers, based on previously clicked button.

    Tomas

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    same principle applies - but either to the recordsource of the form or the filter

  5. #5
    Thomasso is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Thank you.

    Where should I put the code? What event? And when and how do I change the nested form's properties? (for example the data entry form upon clicking on a button in the main menu).

    Also, is it ok to write:
    Code:
    Me.Recordsource = "MY QUERY"
    ?

    Tomas

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    Where should I put the code? What event?
    it would be the click event for each button

    Also, is it ok to write:

    Me.Recordsource = "MY QUERY"
    yes, but if you have spaces you need to use square brackets - "[MY QUERY]"

    better to not have spaces

  7. #7
    Thomasso is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    I tried to implement it like you said, got this error:

    Click image for larger version. 

Name:	err1.PNG 
Views:	16 
Size:	3.6 KB 
ID:	27501

    This is the code:

    Click image for larger version. 

Name:	err2.PNG 
Views:	16 
Size:	16.3 KB 
ID:	27502

    What went wrong?

    Thank you
    Tomas

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    don't know without knowing more about the combo you are trying to update - perhaps the fields are the wrong way round and you are trying to apply text to a numeric bound control

  9. #9
    Thomasso is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    I tried to play with bound controls, no result. What additional information do you need to determine the problem?

    Thank you,
    Tomas

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    a copy of the db - remove unnecessary tables, forms, queries etc. then compact and zip the file

  11. #11
    Thomasso is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Here it is: https://webshare.cz/file/6K15b3dX8s/db-forms-zip

    Just click on "Stáhnout bez VIP". Cannot upload it here for some reason.

    Tomas

  12. #12
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    regret cannot access that site - my AV software won't permit me acess. You should be able to upload to the forum - click on the 'go advanced' button

  13. #13
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    To change a caption on a button and also change what the button does based on the caption, it would be something like:

    If Forms![YourForm]![YourButton].Caption = "Show Form 1" then
    Docmd.OpenForm "Form1"
    Forms![YourForm]![YourButton].Caption = "Show Form 2"
    Else
    Docmd.OpenForm "Form2"
    Forms![YourForm]![YourButton].Caption = "Show Form 1"
    End If

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

Similar Threads

  1. Saving a Record Edit ONLY if button is clicked?
    By McArthurGDM in forum Forms
    Replies: 3
    Last Post: 06-01-2015, 09:33 PM
  2. Replies: 8
    Last Post: 11-21-2014, 04:39 PM
  3. Replies: 4
    Last Post: 05-16-2014, 12:32 PM
  4. Replies: 10
    Last Post: 04-10-2014, 08:24 AM
  5. Replies: 7
    Last Post: 11-30-2013, 12:33 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