Passing a variable from a password form back to code.

G

Guest

I have code that opens a form to input a password. When the password is entered then I click the okay button which causes the form to be invisible. What I want to know is how do I get the information that was typed into the password box assigned to a variable in my code that I can check to verify that the password is correct?

The first part gets the information to check if it is me. If it is me then I have access to the form. If it is not me then they need to enter a password in the form that comes up. This allows me to give a person a password if I need them to do some entries for me and I can change the password at anytime

Please give me examples of what I need to do. I haven't had classes and I have learned by trial and erro

Thanks in advance

Jun

Function CallFormIfAdmin(
' This allows me to access the Data entry form without a passwor
' if it is not me then they need to enter a password

‘ frmDateEntry - form that you need the password to access
‘ frmSubsystems – form used for entering the password. It has the password mask

'-- Define the variables
Dim strUserName As Strin
Dim lngLength As Lon
Dim lngResult As Lon
Dim ap_GetUserName As Strin
Dim strpassword As Strin

'-- Set up the buffe
strUserName = String$(255, 0
lngLength = 25

'-- Make the cal
lngResult = wu_GetUserName(strUserName, lngLength

'-- Assign the valu
ap_GetUserName = strUserNam

‘ Here is where it checks to see if it is me-------------------------------------------------

If ap_GetUserName <> "jecook" The

DoCmd.OpenForm "frmSubsystems", , , , , acDialo

‘ Here is where I need to pass the password to a variable
‘ so that I can check it.
‘ I declared the variable up above as: Dim strpassword As Strin

End I

DoCmd.OpenForm "frmDateEntry

End Functio
 
J

Joe Black

June said:
I have code that opens a form to input a password. When the password is
entered then I click the okay button which causes the form to be invisible.
What I want to know is how do I get the information that was typed into the
password box assigned to a variable in my code that I can check to verify
that the password is correct?
The first part gets the information to check if it is me. If it is me then
I have access to the form. If it is not me then they need to enter a
password in the form that comes up. This allows me to give a person a
password if I need them to do some entries for me and I can change the
password at anytime.
Please give me examples of what I need to do. I haven't had classes and I
have learned by trial and erro.
Thanks in advance,

June

Function CallFormIfAdmin()
' This allows me to access the Data entry form without a password
' if it is not me then they need to enter a password.

' frmDateEntry - form that you need the password to access.
' frmSubsystems - form used for entering the password. It has the password mask.

'-- Define the variables
Dim strUserName As String
Dim lngLength As Long
Dim lngResult As Long
Dim ap_GetUserName As String
Dim strpassword As String

'-- Set up the buffer
strUserName = String$(255, 0)
lngLength = 255

'-- Make the call
lngResult = wu_GetUserName(strUserName, lngLength)

'-- Assign the value
ap_GetUserName = strUserName

' Here is where it checks to see if it is me--------------------------------------------------

If ap_GetUserName <> "jecook" Then

DoCmd.OpenForm "frmSubsystems", , , , , acDialog

' Here is where I need to pass the password to a variable
' so that I can check it.
' I declared the variable up above as: Dim strpassword As String

End If

DoCmd.OpenForm "frmDateEntry"

End Function

Hi June

One way is to declare strpassword as a global variable. You do this at the
top of a module, outside of any sub or function. Then have frmSubsystems
assign the password to this variable (if one is entered).

Public strpassword As String

Function CallFormIfAdmin()
....
strpassword = ""
DoCmd.OpenForm "frmSubsystems", , , , , acDialog
if len(strpassword) > 0 then
if strpassword = MyTempPassword then
DoCmd.OpenForm "frmDateEntry"
end if
end if
....
End Function
 
G

Guest

Thanks for the help. I got the code updated and it seems fine but I can't get the password attached to the variable. I am still trying to figure out the password form. Should I have a subroutine attached to my OK button that gets the variable and will it send it back since it is defined a global. Or, would I be better off to have the OK button call code that is a function. I'm still stuck on how to assign the variable and pick it up in my code.

June
 
J

Joe Black

June said:
Re: getting the variable from one form to code in a module.

I got the correct results in the frmpassword where it checks my password
and if it is correct it loads the database. But then when I go back to the
code and I try to pass the variable it doesn't work. I did set up
strPassword as a Public variable but when I try to use in the the
frmpassword form it complains about it. What am I doing wrong? Thanks for
your help.
June

The code:
At the top of the module after the options I have: Public strPassword As String

Dim strValue As STring
strPassword = ""
DoCmd.OpenForm "frmpassword", , , , , acDialog
strPassword = strValue
If Len(strPassword) > 0 Then

If strPassword = "bear" Then
DoCmd.OpenForm "frmDataEntry"
End If

End If
End If

'DoCmd.Close acform, "frmpassword"
End Function

Here is the frmpassword code:

Private Sub okay_button_Click()
Dim strValue As String

strValue = txtpwd()
Me.Visible = False

End Sub

Hi June

Declare "Public strPassword As String" at the top of a stand alone module,
not a form's module.
(In the VB editor choose menu item Insert > Module)

Assign a value to the global variable in the frmpassword code:

Private Sub okay_button_Click()
strPassword = txtpwd()
Me.Visible = False
End Sub

get rid of strValue in the other module

Regards - Joe
 

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