If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > setfocus from public function?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-12-10, 08:51
dirkjan75 dirkjan75 is offline
Registered User
 
Join Date: Apr 2010
Posts: 15
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')
Reply With Quote
  #2 (permalink)  
Old 04-12-10, 10:21
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
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? ***
Reply With Quote
  #3 (permalink)  
Old 04-12-10, 12:01
dirkjan75 dirkjan75 is offline
Registered User
 
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
Reply With Quote
Reply

Tags
set focus

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On