Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hiding forms with variable name

Status
Not open for further replies.

bistec

Technical User
Dec 12, 2001
16
AU
Hi

I'm playing with passwording forms and although security is not a big issue I'm finding that I'm having to add a few more passworded forms. I though about usernames and passwords but it doesn't really fit into the big picture.

I've created a function (below) that I think will do everything I want but I can't figure out (mental block) a way to set the passed form name to visible or not.

Here's the code

Option Compare Database
Global strGetWord As String
-----------------------------------------------

Function SecurityCheck(strPasswd As String, frmFormName As String, frmReferForm As String, bolCloseRefer As Boolean) As Boolean
Dim OkToGo As Boolean
Dim chances As Integer
Dim frm As Form

' Usage - Call SecurityCheck from button click on refering form
' With accept arguments and return true or false if
' frmReferForm is left blank.
'
' strPasswd is the password required to be able to open the form
' frmFormName is the form that you want to open
' frmReferForm is the form that you started from, the parent form.
' bolCloseRefer True/False whether to close the parent form or hide it
' Example; Call SecurityCheck ("password","nextform",me.name,True)
' Copyright 2003 - Howard Picken

On Error Resume Next
OkToGo = False
chances = 0
' one only gets three chances at a time to get it
Do While chances <= 3
DoCmd.OpenForm &quot;frmpassword&quot;, , , , , acDialog
If strPasswd = strGetWord Then
OkToGo = True
Exit Do
Else
MsgBox &quot;Password Incorrect&quot; & (Chr(13) & Chr(10)) & &quot;Please re-enter or Cancel&quot;, vbOKOnly
chances = chances + 1
OkToGo = False
End If
Loop
If OkToGo Then
SecurityCheck = True
If frmFormName <> &quot;&quot; Then
If bolCloseRefer Then
DoCmd.Close ReferForm
DoCmd.OpenForm frmFormName
Else
Set frm = Form(frmReferForm)
frm.Visible = False
DoCmd.OpenForm frmFormName
End If
End If
Else
SecurityCheck = False
End If

End Function
-------------------------------------------

Function SetWord(strPassIt As String)

strGetWord = strPassIt

End Function
--------------------------------------------

Form frmPassword calls the SetWord function when it close to pass the entered password through to the function.

How do I rewrite the following to work

Set frm = Form(frmReferForm)
frm.Visible = False

Howard
 
One problem (might not be the only one) is that you need to replace
Code:
Form(frmReferForm)
with
Code:
Forms(frmReferForm)
 
Thanks mp9

I had a play tonight at home and found that one.

For anyone that's interested here's the end result.

Option Compare Database
Global strGetWord As String
Global bolCancel As Boolean

Function SecurityCheck(strPasswd As String, frmFormName As String, frmReferForm As String, bolCloseRefer As Boolean) As Boolean
Dim OkToGo As Boolean
Dim chances As Integer
Dim frm As Form

' Usage - Call SecurityCheck from button click on refering form
' With accept arguments and return true or false if
' frmReferForm is left blank.
'
' strPasswd is the password required to be able to open the form
' frmFormName is the form that you want to open
' frmReferForm is the form that you started from, the parent form.
' bolCloseRefer True/False whether to close the parent form or hide it
' Example; Call SecurityCheck (&quot;password&quot;,&quot;nextform&quot;,me.name,True)
' Copyright 2003 - Howard Picken

On Error Resume Next
OkToGo = False
chances = 0
Do While chances <= 2
DoCmd.OpenForm &quot;frmpassword&quot;, , , , , acDialog
If bolCancel Then
Exit Function
End If
If strPasswd = strGetWord Then
OkToGo = True
Exit Do
Else
MsgBox &quot;Password Incorrect&quot; & (Chr(13) & Chr(10)) & &quot;Please re-enter or Cancel&quot;, vbOKOnly
chances = chances + 1
OkToGo = False
End If
Loop
If OkToGo Then
SecurityCheck = True
If nts(frmFormName) <> &quot;&quot; Then
If bolCloseRefer Then
DoCmd.Close ReferForm
DoCmd.OpenForm frmFormName
Else
Forms(frmReferForm).Visible = False
DoCmd.OpenForm frmFormName
End If
End If
Else
SecurityCheck = False
End If

End Function
----------------------------------------
Function SetWord(strPassIt As String, bolCancelit As Boolean)
strGetWord = strPassIt
bolCancel = bolCancelit
End Function
----------------------------------------

I'll post a full example on soon.

Howard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top