0

It seems pretty strange, although the code seems correct I always get back a False Boolean value for:

  • AgencyNameResult = CheckLenght(AgencyName, 2)
  • AgencyWebsiteResult = CheckLenght(AgencyWebsite, 5).

Could you identify the mistake?

Public Function CheckLenght(value As String, CharLimit As Integer) As Boolean

 Dim StringLength As Integer

 StringLength = Len(value)

 If StringLength > CharLimit Then
  CheckLength = True
 Else
  CheckLength = False
 End If

End Function

Private Sub btAddAgency_Click()

Dim AgencyName As String
Dim AgencyWebsite As String,
Dim AgencyNameResult As Boolean
Dim AgencyWebsiteResult As Boolean

Me.tbAgencyName.SetFocus
AgencyName = Me.tbAgencyName.Text
Me.tbAgencyWebsite.SetFocus
AgencyWebsite = Me.tbAgencyWebsite.Text

AgencyNameResult = CheckLenght(AgencyName, 2)
AgencyWebsiteResult = CheckLenght(AgencyWebsite, 5)

....
Erik A
  • 31,639
  • 12
  • 42
  • 67
Sonamor
  • 231
  • 3
  • 17
  • 1
    you have a type error, you Function is `CheckLenght` , and your parameter you use is `CheckLength`. – Shai Rado Jul 15 '16 at 09:06
  • Oh my god, I should have drink that coffee. It was pretty strange. Thanks for your input! – Sonamor Jul 15 '16 at 09:11
  • 9
    This is a prime example why you should always use [`Option Explicit`](http://stackoverflow.com/questions/1139321/how-do-i-force-vba-access-to-require-variables-to-be-defined) :) – arcadeprecinct Jul 15 '16 at 09:12
  • I usually don't program in VBA. Thanks for showing me this option. It will save me in the future. – Sonamor Jul 15 '16 at 09:18

1 Answers1

1

Your function is called

Public Function CheckLenght

Yet, you attempt to assign the return value to

  CheckLength = False

Solution:

rename your function to

Public Function CheckLength
Magisch
  • 7,312
  • 9
  • 36
  • 52