Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    15

    Unanswered: setfocus from public function?

    Hi

    I have the following code, and want to set focus to the control in the field that is send with the function 'contoll'

    Public Function valid_email(ByVal stremail As String, ByVal controll As String) As Boolean

    Dim IsValidE
    Dim regex

    IsValidE = True
    Set regex = New RegExp
    regex.IgnoreCase = False
    regex.pattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
    IsValidE = regex.Test(stremail)
    valid_email = IsValidE
    If valid_email = False Then
    MsgBox "Geen geldig emailadres ingevoerd."
    controll.setfocus



    End If
    End Function

    The controll.setfocus doesn't work obviously, but how can I set focus the field (it's name is email, controll = 'email')

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Pass the control as an actual control, by reference:

    Code:
    Public Function valid_email(ByVal stremail As String, ByRef controll As Control) As Boolean
    At that point you can manipulate the control as you normally would.

    that said, I don't think I'd do that in an email validation routine. Email validation has nothing to do with setting focus to a given control. As such, it makes more sense to let the calling code take care of whatever is supposed to happen after it has been told whether or not the string it passed was a valid email address. This will allow you to reuse your validation code anywhere, regardless of whether or not you care about a specific control while asking for validation.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Apr 2010
    Posts
    15
    Teddy, You are right. I maybe wanted too much, validate an email and if not valid, set the focus to the control that called the function. Maybe better to handle the setfocus in the private sub .
    thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •