How to "Call" a function and where to place the code

G

Guest

Access 2003

I would like to run the function below via a Sub routine like:


********************************
Sub ReplacePassword()
Call myFunction() ' This function generates myString (as A String) which
' represents my OldPassword

Call faqChangePassword(CurrentUser(), myString , Me!NewPassword)
End Sub


Function faqChangePassword(ByVal strUser As String, ByVal strPwd As String,
_ ByVal strOldPwd As String) As Integer

Dim ws As Workspace
Dim usr As User
On Error GoTo err_ChangePassword

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(strUser)
usr.NewPassword strOldPwd, strPwd

err_ChangePassword:
If Err.Number = 3033 Then
MsgBox "You do not have permission to modify passwords. Please contact
your system administrator."
End If

End Function
***************************************


The problem occurs with the Me! Key word. The error states that there has
been an "improper use of Me."

Which module should the ReplacePassword() sub routine be placed? (my guess
= general module)

Which module should the faqChangePassword() sub routine be placed? (not sure?)

Should I make faqChangePassword() a Public function?


I would appreciate some help to make the above work.

Dennis
 
G

George Nicholson

Which module should the ReplacePassword() sub routine be placed? (my
guess
= general module)
If you want to use Me!Password, this code needs to be on the form module
where Password is a field or you'll get "Illegal use of Me".
Which module should the faqChangePassword() sub routine be placed? (not
sure?)
Should I make faqChangePassword() a Public function?

If you place it in the same module as ReplacePassword, it can be Private. If
you put it in a general module, it has to be Public.

BTW,
Call myFunction()
should probably be
myString = myFunction
(unless myString is a global variable, available project-wide, that gets set
by myFunction)

and
Call faqChangePassword(CurrentUser(), myString , Me!NewPassword)
should probably be
Call faqChangePassword(CurrentUser(), Me!NewPassword, myString)
(faqChangePassword expects the passwords in a specific order)

HTH,
 
G

Guest

Thanks for your time George,

I prefer not to use a form. Therefore, what is the smartest way to pass the
data effectively in Me!NewPassword to faqChangePassword() with out "form" use?

Also, should I change the code like below?

Sub ReplacePassword()
myString = myFunction(????, ?????, ????)

Function faqChangePassword(ByVal strUser As String, ByVal _
strPwd As String, ByVal strOldPwd As String) As Integer

Dim ws As Workspace
Dim usr As User
On Error GoTo err_ChangePassword

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(strUser)
usr.NewPassword strOldPwd, strPwd

err_ChangePassword:
If Err.Number = 3033 Then
MsgBox "You do not have permission to modify _
passwords. Please contact your system _
administrator."
End If

End Function

End Sub


Dennis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top