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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access Msgbox?

Status
Not open for further replies.
Mar 29, 2002
33
US
I'm having difficulty with the code for a simple input box that I'm using to input a password. I’ve created the input box and hard coded a password, however I’m having an error come up when I enter in an incorrect password more than one time. I also can’t get the cancel command button on the input box to unload the input box or the close command on the title bar. I’ve listed the code below, if anyone has further questions or can help from what I’ve given, that would be great.
Thanks-

Private Sub Form_Load()
Dim strAns As String
Dim strPwd As String
Dim cmdCancel As CommandButton

strPwd = "password"
strAns = InputBox("Enter Password:", "Password Required")

If "" = strAns Then
Unload Me
ElseIf strPwd <> strAns Then
MsgBox &quot;Wrong Password&quot;, vbInformation
strAns = InputBox(&quot;Enter Password:&quot;, &quot;Password
Required&quot;)
Unload Me
End If

End Sub
 
1) Unload Me is a Visual Basic syntax. Access uses DoCmd.Close. You should be getting an ActiveX error trying to use Unload Me in Access.

2) If you want to do multiple attempts, you need to loop it:

==========
Private Const strPWD As String = &quot;password&quot;

Dim strAns As String

Do
strAns = InputBox(&quot;Enter Password:&quot;, &quot;Password Required&quot;)

If strAns <> &quot;&quot; And Not IsNull(strAns) Then
If strPWD = strAns Then
' Do Whatever ...
Exit Do
DoCmd.Close
Else
MsgBox &quot;Wrong Password&quot;, vbInformation
End If
Else
If MsgBox(&quot;You have not entered a password, do you wish to exit?&quot;, vbQuestion + vbYesNo) = vbYes Then
Application.Quit
End If
End If
Loop
==========

Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top