Results 1 to 11 of 11
  1. #1
    DHaedo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    11

    Making a text box visible/enabled if a listbox is empty

    Hello,
    I have a form that has both list boxes and a subform table pointed at a standalone table. Unique records (ie.PipeMaterial) are displayed in the subform table and common records (ie. ProjectName) are in the List boxes with the row source as "Select Distinct". I want to be able to edit/enable/make visible a text box if the corresponding List box is empty but I am unable to figure out the coding to allow for this.
    I am unsure if I am unable to code the text box due to the "Select Distinct" portion of the List Box.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    txtBox.visible = lstbox.listcount =0

  3. #3
    DHaedo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    11
    Sorry, where would I code that into?

  4. #4
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    where do you want it?
    when user opens the form?
    when user picks an item in a combo?

  5. #5
    DHaedo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    11
    In the form load, I tried this:

    Private Sub Form_Load()
    Me.txtProject.Visible = List12.ListCount = 0
    End Sub


    but it does not work

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    If List12.ListCount = 0 then
    Me.txtProject.Visible = True
    Else
    Me.txtProject.Visible = False
    End If

  7. #7
    DHaedo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    11
    The Listcount property does not work.
    I created another listbox with "=
    [List12].
    [ListCount]" and it only showed "1" regardless of whether there was any data displayed in
    [List12], I think this is because
    [List12] is a Select Distinct [].[] and summarizes the data down. So the ListCount of a summary of Nulls is "1".
    Referencing the table with the Form_Load VBA does not work either.
    I am unable to come up with a workaround solution.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I am not sure what you are trying to do, but there is a difference between the ListCount property and the ItemsSelected property.

    ListCount property
    You can use the ListCount property to determine the number of rows in a list box (list box: A control that provides a list of choices. A list box consists of a list and an optional label.). Read/write Long.

    ItemsSelected property
    You can use the ItemsSelected property to return a read-only reference to the hidden ItemsSelected collection. This hidden collection can be used to access data in the selected rows of a multiselect list box (list box: A control that provides a list of choices. A list box consists of a list and an optional label.) control.

  9. #9
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    You have a list box that shows all the project names and when you click on one, it shows the Materials in he subform? And if you click on a project and it has no materials in the subform, you want to display a text box in the main form?

  10. #10
    DHaedo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    11
    Kinda. I have an asset table with all assets associated with a single project. The Asset table has a project name column, and then various columns about size, diameter, quantity. Each record in this table has the same project name. On the Form I have a list box with (in sql) a Select Distinct [Asset_Table].[Project_Name] query that takes all the records and takes it down to one. The sql code is for when all project name and all associated data with the project is already known and entered.
    When the project name and associated project data is not entered, I need to be able to have a text box become visible/enabled to enter the data into.

  11. #11
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    I think you just need 1 Form. I would put your Select Distinct [Asset_Table].[Project_Name] into a Combo Box(or list box) and put this in the Header of a Form. The Assest data fields for the Project goes in the detail area. When someone selects a Project from the Combo Box, its associated Assets data appear in the detail section. If a project is new(not in the Combo Box), then use wizard to create a New Record button on the Form which will go to a new record for them to enter the fields.

    Or you could have 2 tables (Project and Asset) and do same thing but use a subform for Asset like you talked about.

    Or for your original question, in the OnLoad property of the Form, run the same code that populates your list box (Select Distinct [Asset_Table].[Project_Name]) to check for data, and if none, then make the text box visible. Is the text box for them to enter the Project Name?

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

Similar Threads

  1. Making buttons visible and invisible
    By banpreet in forum Programming
    Replies: 4
    Last Post: 07-29-2016, 08:43 AM
  2. Making form header visible
    By Benton in forum Forms
    Replies: 1
    Last Post: 06-24-2016, 05:39 PM
  3. Replies: 3
    Last Post: 01-22-2015, 12:47 AM
  4. textBox Value making label visible
    By barkly in forum Forms
    Replies: 5
    Last Post: 07-24-2013, 07:05 PM
  5. Making objects visible in a report
    By Lockrin in forum Reports
    Replies: 3
    Last Post: 04-12-2010, 07:06 AM

Tags for this Thread

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