vba code to change a field based on another field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jolaunt
    New Member
    • Apr 2010
    • 16

    #1

    vba code to change a field based on another field

    I am trying to create a vba code to tick a box after an update of another box.

    I have a yes/no drop down box called 'ResolvedByTelC all'. When 'yes' is selected I want a tick to go in another box called 'Resolved'.

    I have tried using the following code which does nothing:
    Code:
    Private Sub ResolvedByTelCall_AfterUpdate()
    If Me.ResolvedByTelCall = True Then
    Me.Resolved = True
    End If
    End Sub
    I am quite new to this and would appreciate any help!!

    Thanks in advance.
    Last edited by NeoPa; Apr 16 '10, 01:08 PM. Reason: Please use the [CODE] tags provided.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    If you have a Drop Down (or ComboBox) then the chances are the values held will be strings rather than boolean or numeric. Your code compares the value to True (which is a boolean value that is numerically equivalent to -1 - or all 1 bits). The value Yes is True. But the value "Yes" is certainly not. Does that make sense?

    Welcome to Bytes!

    Comment

    • jolaunt
      New Member
      • Apr 2010
      • 16

      #3
      Sorry I am a newbie and a little confused by this.

      How do I get around this? Should I change the format of my yes/no box?

      Your help is appreciated

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Try
        Code:
        Private Sub ResolvedByTelCall_AfterUpdate() 
          If Me.ResolvedByTelCall = "Yes" Then 
            Me.Resolved = True 
          End If 
        End Sub
        If that doesn't work, you will need to provide more info on the structure of your drop down (usually referred to as a combobox, since thats what access calls it)

        The box you want to "tick" is that a Checkbox bound to a yes/no field?

        Comment

        • jolaunt
          New Member
          • Apr 2010
          • 16

          #5
          Thank you this worked perfectly! :-)

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            It looks like your ComboBox is populated with string (text) data then. In that case some very simple code should both set and reset it for you :
            Code:
            Private Sub ResolvedByTelCall_AfterUpdate()
              Me.Resolved = (Me.ResolvedByTelCall = "Yes")
            End Sub

            Comment

            Working...