1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: fields switch yes / no automatically

Discussion in 'Business Applications' started by bob12, Jun 4, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. bob12

    bob12 Thread Starter

    Joined:
    Jan 6, 2012
    Messages:
    153
    Friends, I have a subform with two fields yes / no. How do you select only one field to yes?
    That is, if the "A" is set to yes, you can not mark the field "B" to yes, this example is only possible
    mark the field "B" to yes, after clearing the field "A".

    And the reverse, ie, if the "B" is marked
    and yes, you can not mark the field "A" to yes, this example is only possible
    mark the field "A" after clearing the field "B".

    I tried this two codes:

    Private Sub Form_Current()

    If Me.FieldA = -1 Then
    Me.FieldB.Locked = True
    End If

    If Me.FieldB = -1 Then
    Me.FieldA.Locked = True
    End If

    End Sub

    Private Sub Form_Current()

    If Me.FieldA = -1 Then
    Me.FieldB = 0
    End If

    If Me.FieldB = -1 Then
    Me.FieldA = 0
    End If

    End Sub


    In the first works only with the first two records, the third record from the two fields are locked.

    In the second code has no effect.

    Thanks for helping.
     
  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,597
    First Name:
    Hans
    You should try ElseIf,

    You do not have an alternative for Me.FiledA = -1, what happens it it is not -1?
     
  3. bob12

    bob12 Thread Starter

    Joined:
    Jan 6, 2012
    Messages:
    153
    Keebellah, thanks for replying and helping. Sorry, your second sentence was not clear to me, you could say it another way. Thank you.
     
  4. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,597
    First Name:
    Hans
    this is what I mean:

    Code:
    Private Sub Form_Current()
    
    If Me.FieldA = -1 Then
    Me.FieldB.Locked = True
    End If
    
    If Me.FieldB = -1 Then
    Me.FieldA.Locked = True
    End If
    
    End Sub
    
    Private Sub Form_Current()
    
    If Me.FieldA = -1 Then
    Me.FieldB = 0
    [COLOR="red"]Else
     ???????????[/COLOR]
    End If
    
    If Me.FieldB = -1 Then
    Me.FieldA = 0
    [COLOR="Red"]Else
    ?????????????????[/COLOR]
    End If
    
    End Sub
    
     
  5. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    Using VBA code is probably not the best way to do it, ideally you would use an Options Group because it only allows one choice from as many options as you like. That is what they are for.
     
  6. bob12

    bob12 Thread Starter

    Joined:
    Jan 6, 2012
    Messages:
    153
    Keebellah, I did so:

    Private Sub Form_Current()
    If Me.FieldA = -1 Then
    Me.FieldB = 0
    Else
    If Me.FieldB = -1 Then
    Me.FieldA = 0
    End If
    End If




    But not had any effect.

    Obp, two fields are yes / no on a subform, How to use the option group?

    Thank you.
     
  7. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,597
    First Name:
    Hans
    Like this?

    Code:
    Private Sub Form_Current()
    If Me.FieldA = -1 Then
         Me.FieldB = 0
    ElseIf Me.FieldB = -1 Then
         Me.FieldA = 0
    End If
    End Sub
    
    Not If Else End If but If ElseIf End If
     
  8. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,597
    First Name:
    Hans
    I don'tknow what you want to achieve but maybe this example will help

    Your code doesn't tell me what you're really doing

    I agree with OBP that maybe the Option button is a better plan
     

    Attached Files:

  9. bob12

    bob12 Thread Starter

    Joined:
    Jan 6, 2012
    Messages:
    153
    I tried exactly as you posted. but did not work.

    I saw your example, the idea is the same, ie to select an option, another option is unchecked. Only, I repeat,
    I have two fields yes / no on a subform. There's no way I use the option group.

    Thanks for helping.
     
  10. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,597
    First Name:
    Hans
    Well, I can''t pin-point it without a sample.
    Read my PM
     
  11. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,597
    First Name:
    Hans
    LikeI mentioned in my mail to you, I think OBP is the person you nedd when it comes to Ms Access questions. We all assumed Excel because you hadn't mentioned anything and I started with an excel sample.
    The solution I offered may work but like I said, my MS Access knowledge is minumum.
     
  12. bob12

    bob12 Thread Starter

    Joined:
    Jan 6, 2012
    Messages:
    153
    ok, thanks a lot.
     
  13. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    So do you still need help with this?
     
  14. bob12

    bob12 Thread Starter

    Joined:
    Jan 6, 2012
    Messages:
    153
    OBP Hello, sorry I forgot to warn you. Keebellah helped me solve the problem. Thank you.
     
  15. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1055804

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice