Password protect code

J

John Dumay

Hi I have a form that is set as a modal form which propmpts the user for a
password. If successful I want some code to run, otherwise i don't want the
code to run. What i want to do is use this for a number of different codes.
The problem I have is that the underlying code keeps running when I want it
to wait for the answer from the password entry. How do i get the code to wait
until the password form returns a True or False (Variable or function) before
proceding based on that value.

My code looks like this:

Sub BlockedReport()
'Call function to open password form and result = True or False
getPassWord

If getPassWord= True Then
'Do a whole bunch of stuff
Else
'Don't do anything and exit
Exit Sub
End If
End Sub

What happens is it doesn't stop at the 'getPassWord' function and just
continues to run the code before the password can be entered.

Any help ios appreciated.

Regards,

John Dumay
 
N

Neil

John Dumay said:
Hi I have a form that is set as a modal form which propmpts the user for a
password. If successful I want some code to run, otherwise i don't want
the
code to run. What i want to do is use this for a number of different
codes.
The problem I have is that the underlying code keeps running when I want
it
to wait for the answer from the password entry. How do i get the code to
wait
until the password form returns a True or False (Variable or function)
before
proceding based on that value.

My code looks like this:

Sub BlockedReport()
'Call function to open password form and result = True or False
getPassWord

If getPassWord= True Then
'Do a whole bunch of stuff
Else
'Don't do anything and exit
Exit Sub
End If
End Sub

What happens is it doesn't stop at the 'getPassWord' function and just
continues to run the code before the password can be entered.

Any help ios appreciated.

Regards,

John Dumay

===================

Presumably your getPassWord function opens a form, right? Just open the form
as a dialog box, using the acDialog constant in the WindowMode argument.
That will stop execution of the function until the dialog box is closed or
hidden.

Also, I don't understand this code:

getPassWord

If getPassWord= True Then
....

If getPassWord is your function that returns True or False, then where are
you storing the return value? You either need to store the return value in a
variable (and then use the variable in your If statement), or just use the
function directly in your If statement, as follows:

If getPassWord() = True Then
....

Can also just do:

If getPassWord() Then
....

Good luck!

Neil
 

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