Results 1 to 11 of 11
  1. #1
    Foyer is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    12

    Can you Show/Hide fields in a form based on data in another table?

    Hi,

    I want to show a field based on data in another table. On my order form, if I select a customer name, and that customer is listed as a distributor in the customers table (Distributor checkbox = Yes), then I would like a particular field to be visible on my order form.

    I have found tutorials where you can show or hide fields based on data in the current table. Can you do it with data from a different table?



    Thank you.

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Check out the DLookup function.

  3. #3
    Foyer is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    12
    Thanks. So, would the process be 1) add the distributor checkbox as a column to the customer name combobox on my form 2) add a text box using DLookup to extract the distributor checkbox 3) use the value in the text box as the basis for my visible code?

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    foyer-davegri-v01.zip

    Have a look at the quick and dirty attachment.


    Click image for larger version. 

Name:	dlookup.png 
Views:	28 
Size:	25.3 KB 
ID:	46152

  5. #5
    Foyer is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    12
    This wasn't exactly what I needed but your code helped me build my code with just a little tweak, so thank you!

    Private Sub cboCustomer_AfterUpdate()
    If Me.cboCustomer.Column(2) = True Then
    Me.txtAnother.Visible = True
    Else
    Me.txtAnother.Visible = False
    End If
    End Sub

    Although this works in the database your shared, it unfortunately doesn't work in my database because I already have a requery line in AfterUpdate for another field, and I don't know how to combine the two so they both work.

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Or maybe just
    Code:
    Private Sub cboCustomer_AfterUpdate()
    Me.txtAnother.Visible = Me.cboCustomer.Column(2)
    End Sub
    If you post the other relevant code and explain how the other field update is relevant we might be able to help with that.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Foyer is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    12
    Private Sub CustomerCB_AfterUpdate()
    RepCB.Requery
    End Sub

    I have another combobox that will list names of representatives for the customer (the customer is usually a company).

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I still don't understand this
    it unfortunately doesn't work in my database because I already have a requery line in AfterUpdate for another field, and I don't know how to combine the two so they both work.
    It seems you have 2 cascading combo boxes with very similar names (CustomerCB and cboCustomer). Or is it CustomerCB and RepCB?

    Maybe you don't need to worry about it because you have your solution.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I think the OP simply wants to add to the existing code in the customer combo, maybe like this:
    Code:
    Private Sub CustomerCB_AfterUpdate()
    Me.txtAnother.Visible = Me.CustomerCB.Column(2)
    Me.RepCB.Requery 'requery the rep combo
    End Sub
    
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #10
    Foyer is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    12
    Yes, Gicu - that works, thanks!

    Sorry, Micron. I was using davegri's table/field names at first in an attempt to not confuse things, but switched back to my own later rendering that effort null!

  11. #11
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Glad you got it figured out in the end.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. show/hide a picture based on value in table
    By dsmithe in forum Reports
    Replies: 5
    Last Post: 08-22-2018, 03:37 PM
  2. Hide/Show fields at Form based on checkbox
    By cap.zadi in forum Forms
    Replies: 8
    Last Post: 04-22-2016, 05:08 AM
  3. Show/Hide Fields based on criteria.
    By jtm013 in forum Queries
    Replies: 6
    Last Post: 08-14-2014, 08:05 AM
  4. Replies: 7
    Last Post: 02-20-2014, 01:24 PM
  5. Replies: 6
    Last Post: 02-24-2011, 03:24 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