Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

Ok, next let’s try removing some parameters from a function and see what happens. Here is the code I set up for the test in a class module.

HAL_BasicEncryption

Option Compare Database
Option Explicit

Implements IHAL_Encryption

Private Function IHAL_Encryption_decrypt(sEncryption As String, sKey As String) As String
    Debug.Print TestFunction("One", "Two")
End Function

Private Function IHAL_Encryption_encrypt(sInput As String, sKey As String) As String
    Debug.Print TestFunction("First", "Second")
End Function

Private Function TestFunction(Param1 As String, Param2 As String) As String
    Debug.Print Param1
    Debug.Print Param2
    TestFunction = Param1 & Param2
End Function

Now I’m going to highlight the TestFunction definition and tell RubberDuck to Remove Parameters:

And we get the resulting dialog box:

I will double click on the first parameter and click OK.

And here is the new code of the module:

Option Compare Database
Option Explicit

Implements IHAL_Encryption

Private Function IHAL_Encryption_decrypt(sEncryption As String, sKey As String) As String
    Debug.Print TestFunction("Two")
End Function

Private Function IHAL_Encryption_encrypt(sInput As String, sKey As String) As String
    Debug.Print TestFunction("Second")
End Function

Private Function TestFunction(Param2 As String) As String
    Debug.Print Param1
    Debug.Print Param2
    TestFunction = Param1 & Param2
End Function

So we can see the first parameter was removed from the function parameter list, and also the two places it was called, the refactoring process removed the first parameter of each.

However, it did nothing with the code inside the TestFunction and left Param1 referenced inside the function. This causes the code not to compile. I’m not sure what we could expect the refactoring to do otherwise. I suppose just place the removed parameters as local variables inside the function OR make Param1 a private class scoped variable. This at least would have prevented the compilation issue. As it stands now, I just removed the references to Param1 in the function so it could compile again.