HELP WITH FUNCTIONS!!

Milan

Registered User.
Local time
Today, 14:22
Joined
Feb 17, 2002
Messages
85
I AM A NEWBIE!! CAN ANYBODY POINT IN THE RIGHT DIRECTION TO LEARN TO WRITE FUNCTIONS! IN ACCESS 97. I AM OK WITH SUB ROUTINES BEHIND FORMS. BUT HAVE NOT USED THE MODULES PART.. FUNCTIONS. ANY SUGGESTIONS? .

MANY THANKS.
 
No need to shout...
Functions are only different from procedures in that they are designed to return a value. You can put them in the code behind your form or in common modules. The only reason to put them in modules is if you want to call the same function from many modules. Here is an example of a function that clears out dingle quotes from text so that I can pass that text to SQL strings without causing error. This function is called from many forms so it is in a module.

------------------------

Public Function TranslateSQL(field_value As String) As String

Dim strText As String
Dim i As Integer

strText = field_value

For i = 1 To Len(field_value)
If Mid(field_value, i, 1) = Chr(39) Then
strText = Left(strText, i - 1) + Chr(32)
strText = strText + Mid(field_value, i + 1, Len(field_value))

End If
Next i

TranslateSQL = strText

End Function

------------------------

You call a function by assigning it's return value to a variable or control and adding any parameters required by the function in brackets. The declaration of the function defines what parameters are required. In this case I need some text to search...

Dim strConvString as String

strConvString = TranslateSQL(ctlDescription)


---HTH
Chris
 
Just expanding on what chrismcbride said, one big interest of function is that they can return AS MANY values as you want, without using module-level or global variables.
Have a look at BYREF and BY VAL in access help for more details.


Alex
 

Users who are viewing this thread

Back
Top Bottom