Results 1 to 11 of 11
  1. #1
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enable/Disable Control on Open Form (2003)

    Hi you guys,

    I guess i'm asking a lot lately [img]/forums/images/smilies/wink.gif[/img]

    Ok I want to open a form with DoCmd.Open Form stDocName, , , stLinkCriteria

    But I want to disable Forms!frmTest!cboCountry upon opening.
    I tried Forms!frmTest!cboCountry.Enabled = False, but that gives me the error that an object is needed.

    Is there any possibility to Disable something upon opening?

    Dennis

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Enable/Disable Control on Open Form (2003)

    Why don't you set the Enabled property of cboCountry to No in design view?

  3. #3
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Enable/Disable Control on Open Form (2003)

    Ok i guess I didnt make myself clear.

    cboCountry is usually Enabled. Now only when this form is opened by this one button it should be set to Enabled = No

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Enable/Disable Control on Open Form (2003)

    That line of code should work unless the form in question isn't open yet when you try to apply it. If that is the case, open the form hidden first, set the enabled property to false and then make the form visible.
    Charlotte

  5. #5
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Enable/Disable Control on Open Form (2003)

    Yeah I tried but didn't succeed.

    This is the code I got right now:

    -----------------------------------------
    Private Sub OpenParticipating_Click()
    On Error GoTo Err_OpenParticipating_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmSchools"
    stLinkCriteria = "[Year] = [Forms]![frmYear]![cboreg] And [Participation] = True"
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , acHidden
    ' Forms!frmSchools!cboCountry.Enabled = False
    ' Forms!frmSchools.Visible = True

    Exit_OpenParticipating_Click:
    Exit Sub

    Err_OpenParticipating_Click:
    MsgBox Err.Description
    Resume Exit_OpenParticipating_Click

    End Sub
    ----------------------------------------------------------

    What it does? Open the frmSchools in Hidden mode. Now if I unmark Forms!Schools.Visible = True, I get the error message "Object doesn't support this property or method". Running the same thing "Forms!frmSchools.Visible = True" in the "Direct VB Window" shows frmSchools as wanted..... I don't know whats going on here.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Enable/Disable Control on Open Form (2003)

    The code you post should work. Could there be confusion over the name frmSchools? For example, do you have a variable named frmSchools or something like that?

    Does it work if you write the code like this?

    <code>Forms("frmSchools")!cboCountry.Enabled = False
    Forms("frmSchools").Visible = True</code>

    By the way, it shouldn't be necessary to open the form hidden. Setting cboCountry.Enabled = False should happen so quickly that the user never notices it.

  7. #7
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Enable/Disable Control on Open Form (2003)

    hmm no still the same error.

    I added a sample database which reproduces the same error, maybe that helps to solve the problem.

    (It's a .rar file...)

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Enable/Disable Control on Open Form (2003)

    Please attach a zip file instead of a rar file maskerading as a zip file.

  9. #9
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Enable/Disable Control on Open Form (2003)

    done

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Enable/Disable Control on Open Form (2003)

    The form mnuAddresses contains a tab control named RegisterStr16. The first page of his tab control is named Forms. This utterly confuses Access, since Forms is also the name of the collection of open Forms. If you rename the tab page, things will work OK.

    Moral of this story: <big>NEVER give an object or variable the same name as one of the built-in names.</big>

  11. #11
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Enable/Disable Control on Open Form (2003)

    Don't you love those little mistakes which mess up everything? Thanks Hans

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •