IF statment problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Gilmore
    New Member
    • Nov 2006
    • 16

    #1

    IF statment problem

    Below is my code I'm new to coding and don't have much experience I get an error 424 when I try to run it any help would be welcome


    Public Function vatty()

    If Stocktbl.[Vat] = True Then
    Stocktbl.[Total] = "Stocktb.[Price]*1.175"
    Else
    Stocktbl.[Total] = "Stocktbl.[Price]"
    End If


    End Function
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by Richard Gilmore
    Below is my code I'm new to coding and don't have much experience I get an error 424 when I try to run it any help would be welcome


    Public Function vatty()

    If Stocktbl.[Vat] = True Then
    Stocktbl.[Total] = "Stocktb.[Price]*1.175"
    Else
    Stocktbl.[Total] = "Stocktbl.[Price]"
    End If


    End Function
    Where are you calling this function?

    Are you trying to access a table directly? You have to use recordsets for this.

    What are you trying to do and where?

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      The text of the error message would be helpful (as would the line it occurred on), but I think your problem is that you're trying to assign a string to a numeric variable. Try losing the quotes.

      Comment

      • Richard Gilmore
        New Member
        • Nov 2006
        • 16

        #4
        Got it sorted lads

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          Originally posted by Richard Gilmore
          Got it sorted lads
          Just out of curiousity what was the problem?

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            I'm a lad (if a little long in the tooth) but I'm not so sure about Mary.

            PS I'm unashamedly 'Post-whoring' to get to 500 before going to bed tonight ;)

            Seriously though, we're pleased to have helped.

            Comment

            • MMcCarthy
              Recognized Expert MVP
              • Aug 2006
              • 14387

              #7
              Originally posted by NeoPa
              I'm a lad (if a little long in the tooth) but I'm not so sure about Mary.

              PS I'm unashamedly 'Post-whoring' to get to 500 before going to bed tonight ;)

              Seriously though, we're pleased to have helped.
              Adrian

              You whoreeee!!!

              Congratulations ....

              Mary

              Comment

              • PEB
                Recognized Expert Top Contributor
                • Aug 2006
                • 1418

                #8
                Maybe you refer to a form... Form named Stocktb. Am i right?
                So your code should be:
                Code:
                Public Function vatty()
                
                If Forms!Stocktbl![Vat] = True Then
                Forms!Stocktbl![Total] = Forms!Stocktbl![Price]*1.175
                Else
                Forms!Stocktbl![Total] = Forms!Stocktbl![Price]
                End If
                vatty=true
                I've put vatty=true coz every function usually gives result... At least in maths is like this.. y=f(x)

                Here you don't need of x, ok there is no pb for visual Basic... but seems you don't need from y neither??? For visual Basic no pb no more... But it seems if we don't need of y and x we don't need a function need it?

                In fact all you do in your function can be done in your respective form!
                If this is a table... he he sorry impossible... If you tell query -> there is solution but very vewry difficult for u i imagine coz lot of coding!

                Originally posted by Richard Gilmore
                Below is my code I'm new to coding and don't have much experience I get an error 424 when I try to run it any help would be welcome


                Public Function vatty()

                If Stocktbl.[Vat] = True Then
                Stocktbl.[Total] = "Stocktb.[Price]*1.175"
                Else
                Stocktbl.[Total] = "Stocktbl.[Price]"
                End If


                End Function

                Comment

                Working...