I am recieving 424 - Object Required error. What to do?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ibrahim Nohbala
    New Member
    • Dec 2010
    • 4

    #1

    I am recieving 424 - Object Required error. What to do?

    Hello.
    I've written a small program in MS Access 2007 that calculates how many goods left in stock in 3 different units. For example, I have a product that has 3 units of measurement: gr,kg and Piece (P). There are 1000gr in 1kg and 3.5kg in 1P. I'm collecting amounts in minimal units in this example in grams. I want the program to show me the result in all 3 units as there are 4770gr left in my stock. I have a query "mal_hereketi_t am" that calculates how many left in minimal unit. And I tried to write a function code in a module to be able to use in all my reports. I will provide the field names of the query as function's arguments, but the code raises "424 - Object required" error as a result. But it must show 1P1kg270gr. The experimentary piece of my module function is:
    Code:
    Public Function gir_data(Miqdar, u1, u2 As Double, ed1, ed2, ed3 As String, R1 As Integer) As String
    On Error GoTo sehv
    Dim AAA, BBB, CCC As Double
    Dim Baza As Database
    
    Set Baza = CurrentDb
    AAA = Fix(Abs(Miqdar) / u1 / u2)
    BBB = ((Abs(Miqdar) / u1 / u2) - AAA)
    CCC = BBB * u1 * u2
    
    If (Miqdar Is Null Or Miqdar = 0) Then
        gir_data = Null
        Exit Function
    ElseIf (Miqdar < 0 And R1 = 1) Then
        gir_data = "-" & Abs(Miqdar) & ed1
        Exit Function
    ElseIf (Miqdar < 0 And R1 = 3) Then
        gir_data = "-" & AAA & ed3
        Exit Function
    ElseIf (Miqdar > 0 And R1 = 3) Then
        gir_data = AAA & ed3
        Exit Function
    End If
    
    Cixis:
        Exit Function
    
    sehv:
        'gir_data = Err.Number & " - " & Err.Description
        gir_data = Round(AAA, 3) & ed3
        Resume Cixis
    
    End Function
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    A few things immediately throw up Red Flags:
    1. The possibility exists, as indicated in Code Line #12, that the Function can return a NULL Value, yet its Return Value is Declared as String. This is a No-No, the Return Value of the Function must be Set to Variant.
    2. Within the If...ElseIf...E nd If Clause, you have several Exit Function Statements which are not needed, since only a Single Condition will be evaluated and the Code will exit the Function anyway after the Cixis Label.
    3. Code Lines 4 and 6 server no real purpose within the Function, and have been removed.
    4. Be aware that since the Parameters Miqdar, u1, ed1, and ed2 have not specifically been cast as far as specific Data Types, they are considered Variants.
    5. You may wish to consider a Fall Through condition which will apply if none of the other Conditions are met (Else Clause).
    6. The Revised Code is posted below:
      Code:
      Public Function gir_data(Miqdar, u1, u2 As Double, ed1, ed2, ed3 As String, R1 As Integer) As Variant
      On Error GoTo sehv
      Dim AAA, BBB, CCC As Double
        
      AAA = Fix(Abs(Miqdar) / u1 / u2)
      BBB = ((Abs(Miqdar) / u1 / u2) - AAA)
      CCC = BBB * u1 * u2
        
      If (Miqdar Is Null Or Miqdar = 0) Then
        gir_data = Null
      ElseIf (Miqdar < 0 And R1 = 1) Then
        gir_data = "-" & Abs(Miqdar) & ed1
      ElseIf (Miqdar < 0 And R1 = 3) Then
        gir_data = "-" & AAA & ed3
      ElseIf (Miqdar > 0 And R1 = 3) Then
        gir_data = AAA & ed3
      Else
        'fall through condition
      End If
        
      Cixis:
        Exit Function
        
      sehv:
        gir_data = Round(AAA, 3) & ed3
          Resume Cixis
      End Function

    Comment

    • ibrahim Nohbala
      New Member
      • Dec 2010
      • 4

      #3
      Dear ADezii, thank you for your reply. I've corrected the lines as you adviced, but the problem still exists. Function still returns the same error... What else it can be?

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Try a change in Syntax on Code Line #9, it should read:
        Code:
        If (IsNull(Miqdar) Or Miqdar = 0) Then

        Comment

        • ibrahim Nohbala
          New Member
          • Dec 2010
          • 4

          #5
          Still not working... Error the same...

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Post 'your' Revised Code, and some examples of Values that you are passing to this Function.

            Comment

            Working...