Enter a function - Very basic help

  • Thread starter Thread starter Ed Morgan
  • Start date Start date
E

Ed Morgan

I need to verify that an email address doesn't contain any common errors. I
copied a function from someone on the AccessListServe, but I don't know what
to do with it. It needs to work after the text box for the email address has
been updated (AfterUpdate property) How do i store the function (or any
function for that matter)so that i can call it from the property sheet?
Thanks,--
Ed Morgan
 
I assume you are working on a form

In the design view of the form, right click on the text box and select
properties.
To to the events tab, select the After Update event, click the selection box
(on the right end) and choose eventprocedure
Hit the three dots (wizard) button to open the VBA screen
Paste your code
Say a prayer
Test
 
The function should go into a standard module (not a form or class module)
with a declaration of Public Function.... (this lets it be visible
throughout the project).

Lets pretend this function is declared as so:

Public Function fCheckEmail(emailaddr As String) As Boolean


As a side note, I would use BeforeUpdate to verify that the info is entered
correctly rather than AfterUpdate.

Anyway, from your properties sheet, create some code for the BeforeUpdate
event procedure. You will need to call the function from there. It will
look like this:

Private Sub Form_BeforeUpdate(Cancel As True)
If fCheckEmail(Me.EmailTextbox) = False Then
MsgBox "Please enter the email correctly"
Cancel = True
End If
End Sub


(setting cancel = true cancels the update of the textbox, rather than using
afterupdate, in which case you can't be sure that they will actually go back
and change it)


hth



--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
That nearly gets me there - i think. How do you declare a function?

Anatomy of a function/sub:



Private Function SomeName() As Datatype <-- Declaration

'your code here <-- Body

End Function <-- Closing



Functions can be declared as Private or Public (for the most part). When
you type "Public Function Somename()" and hit enter to go to the next line
access will automatically put the End Function line (or End Sub if you are
writing a sub rather than a function). And then type your code between those
two lines.

h
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Back
Top