By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,647 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,647 IT Pros & Developers. It's quick & easy.

Do I need the "Public" in the following... Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef sReason As String) As Boolean

P: n/a
MLH
The following function declaration confuses me...

Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef
sReason As String) As Boolean

I tried pasting it and its code into an Access 2.0 module. I was
unsuccessful. I had to remove the following...
"Public"
"Optional ByRef"
"As Boolean"

I replaced the "As Boolean" with "As Integer". Then it all worked.
What's the "Public" and "Optional ByRef" for anyway?
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
MLH wrote:
The following function declaration confuses me...

Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef
sReason As String) As Boolean

I tried pasting it and its code into an Access 2.0 module. I was
unsuccessful. I had to remove the following...
"Public"
"Optional ByRef"
"As Boolean"

I replaced the "As Boolean" with "As Integer". Then it all worked.
What's the "Public" and "Optional ByRef" for anyway?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Public" means the function is "visible" to all possible calling
routines (the Public is allowed to use it).

"Optinal ByRef" means the parameter is an optional parameter (it may, or
may not be used by the calling routine) and that instead of the actual
parameter value there is a pointer to the value. A pointer is an
address in the computer's memory that "points" to the variable value
(or, sometimes, another pointer - don't worry about it). The converse
to ByRef is ByVal which means the actual parameter value has been passed
to the function/sub.

"As Boolean" means the value returned by the Function will be a Boolean
(True/False - in VBA True = -1; False = 0) value.

I believe all these terms were introduced into Access VBA in
Access/Office 97 - not sure. That's why they don't work in Access 2.
Ya really have to upgrade to a newer version :-).

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQijUToechKqOuFEgEQK5SACgwixwE11OdugS8vjTob10VW nT/UcAn0lj
AObQXErYVkkXy2cJRHL6Abg3
=5kl6
-----END PGP SIGNATURE-----
Nov 13 '05 #2

P: n/a
"MGFoster" <me@privacy.com> wrote in message
news:fv***************@newsread3.news.pas.earthlin k.net...
MLH wrote:
The following function declaration confuses me...

Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef
sReason As String) As Boolean

I tried pasting it and its code into an Access 2.0 module. I was
unsuccessful. I had to remove the following...
"Public"
"Optional ByRef"
"As Boolean"

I replaced the "As Boolean" with "As Integer". Then it all worked.
What's the "Public" and "Optional ByRef" for anyway?


"Public" means the function is "visible" to all possible calling
routines (the Public is allowed to use it).

"Optinal ByRef" means the parameter is an optional parameter (it may, or
may not be used by the calling routine) and that instead of the actual
parameter value there is a pointer to the value. A pointer is an
address in the computer's memory that "points" to the variable value
(or, sometimes, another pointer - don't worry about it). The converse
to ByRef is ByVal which means the actual parameter value has been passed
to the function/sub.

"As Boolean" means the value returned by the Function will be a Boolean
(True/False - in VBA True = -1; False = 0) value.

I believe all these terms were introduced into Access VBA in
Access/Office 97 - not sure. That's why they don't work in Access 2.
Ya really have to upgrade to a newer version :-).


Even in Access 97, I don't believe you can declare Optional and As String
unless you define a default value: you have to use As Variant.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

Nov 13 '05 #3

P: n/a
Douglas J. Steele wrote:

Even in Access 97, I don't believe you can declare Optional and As String
unless you define a default value: you have to use As Variant.


IIRC you only needed "As Variant" if you wanted to check for IsMissing()
otherwise the default value of a string ("") or number (0) will be
passed. Can't quite remember if "optional" was in 97 or not, long time
since I used it.

--
This sig left intentionally blank
Nov 13 '05 #4

P: n/a
"Trevor Best" <no****@besty.org.uk> wrote in message
news:42**********************@news.zen.co.uk...
Douglas J. Steele wrote:

Even in Access 97, I don't believe you can declare Optional and As String
unless you define a default value: you have to use As Variant.


IIRC you only needed "As Variant" if you wanted to check for IsMissing()
otherwise the default value of a string ("") or number (0) will be passed.
Can't quite remember if "optional" was in 97 or not, long time since I
used it.


You convinced me to go test it, and right you are. In fact, if you declare
the parameter As Variant, you must use IsMissing with it. If it is missing,
you'll get an error if you try to refer to it.

Yes, Optional is available in 97

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.