VB code in Access 2007 Event Procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mroberts50
    New Member
    • Sep 2010
    • 4

    VB code in Access 2007 Event Procedure

    On my form I have an option box for Band Option and a field box for Band Amount. When I click the Band Option box I want it to fill in the Band Amount field for 500. But it will not work and I cannot figure out why. Here is the code I am using, my option is True/False.

    Private Sub Band_Option_Aft erUpdate()
    If (Me!Band_Option ) = ["True"] Then
    Me!Band_Price = "500"


    Else
    If (Me!Band_Option ) = ["False"] Then
    Me!Band_Price = "0"


    End If
    End Sub
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    #2
    Code:
    Private Sub Band_Option_Click()
    If Me!Band_Option = True Then
    Me!Band_Price = 500
    
    Else
    Me!Band_Price = 0
    End If
    
    End Sub
    You had one too few 'End If' statements.
    'True' is a keyword for boolean (True/False) comparisons.
    'If Me!Band_Option = False' not necessary if If Me!Band_Option can only be True or False, and it is not True from 1st test.

    Comment

    • mroberts50
      New Member
      • Sep 2010
      • 4

      #3
      VB code in 2007 Accesss

      Private Sub Band_Option_Cli ck()
      If Me!Band_Option = True Then
      Me!Band_Price = 500

      Else
      Me!Band_Price = 0
      End If

      End Sub

      Thanks Birdmand but It still does not fill in the amount field to 500.

      Comment

      • OldBirdman
        Contributor
        • Mar 2007
        • 675

        #4
        What does happen, if anything?
        Try putting the line
        Code:
        MsgBox "Amount = " & Me!Band_Price
        before the 'End Sub' statement. That will tell you what is in Band_Price, if anything.
        If you don't get a message box after doing the above, then the event isn't being triggered. Go to the properties box of Band_Option and be sure the 'On Click' event has '[Event Procedure]' in it. If not, select it from the choices. Then click the ellipsis (three dots ...) and see if you are taken to the correct code.
        Post results of your efforts, what is right, what is wrong.

        Comment

        • OldBirdman
          Contributor
          • Mar 2007
          • 675

          #5
          If the above doesn't solve your problems, someone will have to take over this thread. I'm going to be away for a few weeks, often without internet connections, and definitely without the time to continue.

          Comment

          Working...