Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Jan 2010
    Posts
    32

    Unanswered: enabling buttons

    Thanks for all good help you guys offer!

    I have a listbox form that displays a list used for multiple reasons. I.E. it lists templates and you can select them to be modified, to view a summary, etc. This listbox is launched from other forms.
    Question: Is there a way to have multiple buttons on this list box but only enable certain ones depending on which form launched it?

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Sure; you can use OpenArgs to pass the name of the calling form. In this form's open event, test OpenArgs and enable buttons appropriately. More info on OpenArgs in VBA help.
    Paul

  3. #3
    Join Date
    Jan 2010
    Posts
    32
    I have successfully passed this to the next form. It works..BUT. I have different buttons on the same calling form opening the next form and enabling buttons. How do I pass the button as well as the form information?

    Here is what I have so far...you can see it is not going to work because the name is the same:

    Private Sub Form_Load()
    Select Case Me.OpenArgs
    Case "frmflowchart"
    Me.Command13.Enabled = True
    Case "frmflowchart"
    Me.Command3.Enabled = True

    End Select
    End Sub

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I'm not clear what you're after, as the example code could simply be

    Select Case Me.OpenArgs
    Case "frmflowchart"
    Me.Command13.Enabled = True
    Me.Command3.Enabled = True

    If you need to know what button was pressed on the calling form as well as what form, you can pass both separated by some delimiter ("FormName;ButtonName") and then parse them out.
    Paul

  5. #5
    Join Date
    Jan 2010
    Posts
    32
    I wish I could use that simplified one but as you suggested, I do need to enable a particular button depending on what button was pressed on 1st form (frmflowchart).

    here is the event code behind both buttons on the "frmflowchart"...

    DoCmd.OpenForm "frmiepselection", , , stLinkCriteria, , , Me.Name

    here is the adjusted code behind the onload event event of the 2nd form (frmiepselection):

    Select Case Me.OpenArgs
    Case "frmflowchart;Label408"
    Me.Command13.Enabled = True
    Case "frmflowchart;Label407"
    Me.Command3.Enabled = True

    End Select

    Didn't work when I tried it.

    Thanks!

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Me.Name is only passing the name of the form. Look at ActiveControl to get the name of the selected button (if you're actually using buttons). You'd have to concatenate the two together along with the delimiter.
    Paul

  7. #7
    Join Date
    Jan 2010
    Posts
    32
    That's a great point...now that I look at this, those dont act like buttons. You may have to point me to the ActiveControl.

  8. #8
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    They have names that indicate they might be labels. You can use a label like a button, but be aware that since it can't have focus, ActiveControl won't work. More info on ActiveControl in VBA help.
    Paul

  9. #9
    Join Date
    Jan 2010
    Posts
    32
    Ok...The example they use sort of makes sense to me. But where would I put a statement like that?

  10. #10
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    DoCmd.OpenForm "frmiepselection", , , stLinkCriteria, , , Me.Name & ";" & PutItHere
    Paul

  11. #11
    Join Date
    Jan 2010
    Posts
    32
    So let me ask you this.

    If I were to change the labels to buttons would this work:

    DoCmd.OpenForm "frmiepselection", , , stLinkCriteria, , , Me.Name & ";" & "ButtonName"

  12. #12
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    That would work either way. My point was that you can't use ActiveControl with labels.
    Paul

  13. #13
    Join Date
    Jan 2010
    Posts
    32
    This gets me a 438 runtime with "object not supported:

    DoCmd.OpenForm "frmiepselection", , , stLinkCriteria, , , Me.Name & ";" & Label408

  14. #14
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    In your question as to whether it would work, you properly put quotes around the label name. Here you've dropped them.
    Paul

  15. #15
    Join Date
    Jan 2010
    Posts
    32
    Good Call....I added those...didn't get the error but it still didn't enable the button. Do I need to seperate these with quotes?

    Select Case Me.OpenArgs
    Case "frmflowchart;Label408"
    Me.Command13.Enabled = True
    Case "frmflowchart;Label407"
    Me.Command3.Enabled = True

Posting Permissions

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