Results 1 to 4 of 4
  1. #1
    terjeo is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    11

    Hide a button in the main form when a field in a sub from is empty

    I have a main form called "Main", and a sub form called "Edit". In the form "Edit" there is a field called "Other_info".

    When the field "Other_info" is blank, I want to hide the button "Other Info" in the main form.

    I try to use the IsNull function, but I need help for the whole string.

    I hope this is understandable.



    Thank you for all help.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    What view is the subform in the main form? If it's a continuous or datasheet view it will depend on which record is the active/selected record and what the value in that field is on that record. Thus the button might be seen if on one record but not if on another. If the subform is only showing one record, then it will depend only on that record. I'd say it's a bit unusual to show only one record in a subform but thought it best to ask.

    You could try this on the subform in the Current event:

    If Len(Me.Parent.Other_info) & vbNullString = "" Then Me.Parent.myCommandButton.Visible = False
    Could also use Nz function: If Nz(Me.Parent.Other_info,"") = "" Then...

    I might have the Parent reference incorrect - I rarely use it.

    EDIT - corrected reference to button. It was pointing to the subform, not the main form.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I would assume that the subform is tied to the mainform in some way?
    So on the subform current event
    Code:
    me.parent.cmdOther_Info.visible = len(me.other_info & "") > 0
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    terjeo is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    11
    The main form is read only, and the sub form is where I edit the data. Both forms show only one record at the time. The database is a member register.
    I will try what you suggest.

    Thanks

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

Similar Threads

  1. Hide Field in Subform with Button
    By zplatt98 in forum Forms
    Replies: 5
    Last Post: 04-08-2019, 01:53 PM
  2. Replies: 3
    Last Post: 08-16-2018, 09:52 AM
  3. Can I disable a button if a field is empty (null)?
    By Tall_Paul in forum Programming
    Replies: 9
    Last Post: 02-03-2018, 05:59 PM
  4. Replies: 6
    Last Post: 02-23-2016, 01:45 PM
  5. Subform empty when main form loaded
    By martyjward in forum Forms
    Replies: 1
    Last Post: 08-15-2011, 04:37 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