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)

....
4
  • 1
    you have a type error, you Function is CheckLenght , and your parameter you use is CheckLength. Commented Jul 15, 2016 at 9:06
  • Oh my god, I should have drink that coffee. It was pretty strange. Thanks for your input! Commented Jul 15, 2016 at 9:11
  • 9
    This is a prime example why you should always use Option Explicit :) Commented Jul 15, 2016 at 9:12
  • I usually don't program in VBA. Thanks for showing me this option. It will save me in the future. Commented Jul 15, 2016 at 9:18

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.