Results 1 to 8 of 8
  1. #1
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314

    Need a form control to not retrieve data from a table when not needed

    I have a table for Sites, which includes name and type, among other fields.
    I have a Asset transaction table which links Assets to Members (Custodians) and Sites, to provide historical status information about assets.
    The Asset Transaction form includes a combo box to select a member as Custodian, a combo box to select a Site and control to display the Site Type from the Sites table, among other controls.

    As it is now, the sub-form, under Assets, requires me to select a site, or it reports Site_ID cannot be found (when none has been selected). It is the Site_Type control, which is causing this error.

    I need the Site_Type display control to retrieve the Site_Type data from the Site table, only when the Site Combo box has selected a Site, in which case, both the [Site] Combo box and the [Site_ID] will have a value.



    After several different attempts to tell the Site_Type control not to retrieve data when a site has not been selected, I cannot figure out how to do this.
    The Sites.Site_Type happens to be combo box to select Types for Sites. Since the control in this context is for display only, I have it disabled. I also tried using a simple text field to display the site type, but, of course it still attempts to retrieve data when no site has been selected.

    The two controls in the sub-form are highlighted.
    Attached Thumbnails Attached Thumbnails Site Type.JPG  

  2. #2
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    After I posted this query, I kept trolling the Internet for a solution, and came across this one:
    In the sub-form, I replaced the Site_Type field from the Sites table, with an unbound text box.
    Then in the After update property for the Sites combo-box (which already included the Site_Type column), which I was already using to assign the Site_ID, I added a second command to save Site.Column(2) into the unbound control.
    It does just what I need it to do, so I'll mark this post as Solved.
    Code:
    Private Sub Site_AfterUpdate()
        Site_ID = Site.Column(0)
        SiteType = Site.Column(2)
    End Sub
    Since the unbound control is for display only, I disabled it, to avoid confusion.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    1) You could also concatenate the SiteName and the SiteType in the Site combo box. Wouldn't need the unbound Text box.

    The combo box Row Source would look something like
    Code:
    SELECT Site_ID, SiteName & " - " & SiteType As SiteNameType, AnotherField FROM tblSites;
    Then set the combo box properties:
    Bound Column = 1
    Column Count = 2
    Column Widths = 0



    Or
    2) You could add a field to the Sites table for the concatenated SiteName/SiteType, then modify the SQL for the combo box Row Source.

  4. #4
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Thanks. I like the first option better. I was trying to have the combo box show two fields after selection, but I guess that can't be done. So, your first option will fit the bill.

  5. #5
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    I implemented your option 1 and it works fine. Thanks again.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You're welcome....

  7. #7
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    I posted another problem in the Forms forum. Can you help with it?

  8. #8
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314

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

Similar Threads

  1. retrieve data from unbound control on form
    By Abacus1234 in forum Queries
    Replies: 6
    Last Post: 08-04-2015, 05:31 PM
  2. Replies: 2
    Last Post: 05-29-2015, 09:21 AM
  3. Replies: 22
    Last Post: 01-23-2014, 02:13 PM
  4. Replies: 1
    Last Post: 03-09-2012, 07:43 PM
  5. Replies: 1
    Last Post: 05-17-2011, 05:19 AM

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