• If witout block (Access2000-03)

    Author
    Topic
    #445741

    Hi,
    I have 2 combo boxes.
    When value in one is selescted – another should get disabled so value can’t be picked out of that one.
    It is either – or!

    So would this be valid? So far it is not working – giving me an error If without BlockIf etc…:

    If ID_Name.Value = True Then BUSINESS_UNIT.Enabled = False
    Else
    If BUSINESS_UNIT.Value = True Then ID_Name.Enabled = False
    End If

    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #1081588

      You are missing a second End If (it’s clearer with indenting):

      If ID_Name.Value = True Then
      BUSINESS_UNIT.Enabled = False
      Else
      If BUSINESS_UNIT.Value = True Then
      ID_Name.Enabled = False
      End If
      End If

      Nick

      • #1081590

        Thank you, Nick.
        I am trying to let user to select from one cmb.box only
        However that code of mine does not disabling anything.
        Am I using wrong property?

        • #1081613

          Try this:

          Private Sub Business_Unit_AfterUpdate()
          Me.ID_Name.Enabled = IsNull(Me.Business_Unit)
          End Sub

          Private Sub ID_Name_AfterUpdate()
          Me.Business_Unit.Enabled = IsNull(Me.ID_Name)
          End Sub

          • #1081619

            Cool!
            But what it does – it let’s me pick the value from the first one.
            Then it let’s me pick value from the second one and when value in second one is PICKED – it greys out the FIRST one.

            I am going to play with it now. Thanks any changes you can think of – please, pass them onto me.?

            • #1081623

              Here is a slightly fancier version:

              Private Sub Business_Unit_AfterUpdate()
              If IsNull(Me.Business_Unit) Then
              Me.ID_Name.Enabled = True
              Me.ID_Name.SetFocus
              Else
              Me.ID_Name.Enabled = False
              End If
              End Sub

              Private Sub ID_Name_AfterUpdate()
              If IsNull(Me.ID_Name) Then
              Me.Business_Unit.Enabled = True
              Me.Business_Unit.SetFocus
              Else
              Me.Business_Unit.Enabled = False
              End If
              End Sub

            • #1081627

              It does exactly the same thing as I described above.
              It should be like this:
              If value in the first one picked – second gets disabled.
              And vise versa.
              Or maybe if one value was picked – try to touch another and get message ‘You are not allowed to select another value’…

              I think first way is cleaner…
              Thanks

              P.S. I had just tried again and I am thinking both are should be enabled (in case they changed their mind and wanted to print Report for another parameter) – so the way is to keep both combo boxes enabled BUT IF value in one was picked – if user tries to pick the value in another one – error message.
              They need to be force to delete the value from the first and pick in the second one IF they happened to change their mind…

            • #1081633

              My code does what you want – see attached demo.

            • #1081634

              Of course…I forgot to set properties of combo boxes to [event procedure] and have the correct ones to it!
              THANKS

            • #1081641

              Yep! I need that message so both are staying Enabled BUT if one value is already picked – if second box touched by accident or on purpose – error message comes up.
              I can see how they can easily pick in a wrong box and the way it is now – no stepping back.
              Thanks

            • #1081647

              They can always clear the combo box, as soon as they tab out of it, the other one will be enabled.

            • #1081652

              I’d tried.
              When I clicked on the button to run the Report second disabled box gor back to enable state.
              But IF they want to clear one they had picked – another one is dead and no way it can be ressurected unless they run Report first…
              Am I wrong?

            • #1081656

              In the demo I posted, all you need to do is clear the combo box that is filled, then press tab. The other one will be enabled instantaneously. If both combo boxes are cleared, both will be enabled. No need to run a report first, or anything like that.

            • #1081664

              Yep! The step of pressing the tab is very inconvenient. Is it avoidable? Thanks

            • #1081665

              If the user doesn’t press Tab, Access doesn’t know that the combo box has been cleared.

              Another option would be to leave both combo boxes enabled, and to perform a check afterwards, for example in the Before Update event of the form, or in the On Click event of a command button.
              This means that the user can select an item in both combo boxes without problems. The warning will be issued later.

            • #1081666

              I want advise.
              I wrote this

              Private Sub Business_Unit_Click()
              On Error GoTo ErrHandler

              Me.BUSINESS_UNIT.Enabled = False

              ErrHandler:
              If Err = 2501 Then
              ‘ Report canceled – ignore this
              Else
              MsgBox Err.Description, vbExclamation
              End If

              I am clicking OK to am error message and now I need combo box to get cleared. It would be perfect solution.
              Yes and I also need correct error message. Thanks

              End Sub

            • #1081682

              Sorry, I don’t understand this code. You’re disabling Business Unit if the user clicks on it? scratch

            • #1081730

              OK you have GOT TO be roud of me!
              I had accomplished exactly what I wanted.
              Look please and comment on how to improve:

              Private Sub Recruiter_ID_Name2_AfterUpdate()

              If IsNull(Me.BUSINESS_UNIT) Then
              Me.Recruiter_ID_Name2.Enabled = True

              Else
              MsgBox “Only one parameter allowed for this Report!”, vbExclamation
              Me.Recruiter_ID_Name2 = Null

              End If

              End Sub

              Private Sub Business_Unit_AfterUpdate()

              If IsNull(Me.Recruiter_ID_Name2) Then
              Me.BUSINESS_UNIT.Enabled = True

              Else

              MsgBox “Only one parameter allowed for this Report!”, vbExclamation
              Me.BUSINESS_UNIT = Null
              End If

              End Sub

            • #1081742

              You’re making it too difficult. If you don’t want to use the code I provided, you could do the following:

              – Create an option group with two options: Name ID and Business Unit.
              – In the After Update event of the option group, enable Name ID and disable Business unit if the first option has been selected, and the other way round if the second option has been selected.

            • #1081755

              But it wasn’t clearing unwanted values…

              Anyway after all blood and sweat I was asked to create 2 separate instances.
              Don’t we all just love our users? 🙂

              Thanks

    Viewing 0 reply threads
    Reply To: If witout block (Access2000-03)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: