• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1483
  • Last Modified:

Using VBA to Ref. Form Detail section

Please Help,  am having trouble enabling and disabling the detail section (section 0) of a form.
 
Have tried variations on the code below to no avail.
The error message states that Section() or Detail1 are invalid field names.  This is true, but then how can you refer to the section name or number.
 
    Me!Section(0).enabled = True
   Forms![customers].Section(0).enabled = True
   
  Forms![Customers].Detail1.enabled = True
 
Me!Detail1.Enabled = True
0
spurs1999
Asked:
spurs1999
1 Solution
 
PShieldsCommented:
enable is not a valid property for a section.  You can set the visible property.  I use the following function  to loop through controls to lock them.
ctlstate is either true or false
Public Sub lockct(ctlstate)
Dim frm As Form, ctl As Control

    Set frm = Forms!Families
    ' Enumerate Controls collection.
    For Each ctl In frm.Controls
        If ctl.ControlType = acComboBox Then
        ' Set control properties.
            With ctl
                .Locked = ctlstate
            End With
        End If
        If ctl.ControlType = acTextBox Then
            ' Set control properties.
            With ctl
                .Locked = ctlstate
            End With
        End If
        If ctl.ControlType = acSubform Then
        ' Set control properties.
            With ctl
                .Locked = ctlstate
            End With
        End If
    Next ctl


0
 
JimMorganCommented:
Spurs1999:  Pshields is absolutely correct about the Visible property.  Do accept his answer.

Pshields:  Welcome to EE:

This seems to be your first answer to a question and it is spurs1999 first question on EE.

May I give you some advice.  We don't know the expertise level of spurs1999 so we have to assume it is novice.

If this is true, then spurs1999 would benefit greatly if the proposed answer were along these lines.  (BTW, this was a simple one to answer.  The answer is to use the Visible property.)

spurs1999:  I'm afraid that Access is misleading you by giving you error message states that Section() or Detail1 are invalid field names.  This should have been a clue that if Access thought they were field names and they are not that there might be another property that should be used.

The correct property is Visible.

   Me.Detail.Visible = False


Then you could explain to spurs that there is a lot of information within Access once you learn to use it.  Help has a lot of data, however it is probably best to use Find instead of Content or Index.  You can use the Object Browser to find which properties are available for an object.  Then you could go into more specifics about how to use the Object Browser.  This is always good knowledge not only for the question asker but the few thousands of members who only look and read these threads.

The looping through controls is good code but it may be way over a member's head without a lot of explanation about why you are suggesting it and how it should be used.  Too much unnecessary information might confuse someone new and frighten them away.  I'm not saying that this would happen here, just some observations.

Any way welcome to the EE and the topic.  We are always looking for new experts to keep the old timers on their toes.

Jim
0
 
MoondancerCommented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed.  Also a question is posted there specific to these changes that apply to the experts here.  Also, I am including the link to our All Topics, since many new ones have recently been added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now