473,387 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

User logon form issue: Cancel button behaviour changing?!

374 256MB
I use the following code to manage user logon success:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOk_Click()
  2. On Error GoTo Err_cmdOk_Click
  3. '-----------------------------------------------------------------------------------------------------------------------------
  4. ' This code is used to validate users found in the tblSecurity table. If the wrong user name or password is
  5. ' provided access is denied.
  6. '-----------------------------------------------------------------------------------------------------------------------------
  7.     Dim db As DAO.Database
  8.     Dim rst As DAO.Recordset
  9.     Dim rstV As Recordset
  10.     Dim stDocName As String
  11.     Dim stLinkCriteria As String
  12.  
  13.     Set db = CurrentDb()
  14.     Set rst = db.OpenRecordset("tblSecurity", dbOpenDynaset)
  15.  
  16.     If Not IsNull(Me.txtUser) And Not IsNull(Me.txtPassword) Then
  17.         rst.FindFirst "Password = '" & Me.txtPassword & "'" & " And UserID = '" & Me.txtUser & "'"
  18.  
  19.         If rst.NoMatch Then
  20.             MsgBox "You entered the wrong User Name or Password." & Chr(13) & _
  21.             "Please enter the correct User Name and Password or " & Chr(13) & _
  22.             "contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
  23.         ElseIf Me.txtPassword = "password" Then
  24.             MsgBox "This is the first time using the database or your passowrd has been reset." & Chr(13) & _
  25.             "You must change your password before you can enter the database.", _
  26.             vbOKOnly + vbExclamation, "Change Password"
  27.             stDocName = "frmUserLogonNew"
  28.             stLinkCriteria = "[UserID]=" & "'" & Me![txtUser] & "'"
  29.             DoCmd.OpenForm stDocName, , , stLinkCriteria
  30.         Else
  31.             stDocName = "frmSplashScreen"
  32.             DoCmd.OpenForm stDocName, , , stLinkCriteria
  33.         End If
  34.     Else
  35.         MsgBox "You left the User Name and/or Password blank." & Chr(13) & _
  36.         "Please enter the correct User Name and Password or " & Chr(13) & _
  37.         "contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
  38.     End If
  39.  
  40.  
  41.     With Forms!frmhidden
  42.         .txtViewID = rst.Fields("ViewID")
  43.         .txtAccessID = rst.Fields("AccessID")
  44.         .txtActive = rst.Fields("Active")
  45.         .txtPassword = rst.Fields("Password")
  46.         .txtUserID = rst.Fields("UserID")
  47.         .txtSecurityID = rst.Fields("SecurityID")
  48.         .txtFName = rst.Fields("FName")
  49.         .txtSName = rst.Fields("SName")
  50.         .txtEMailAd = rst.Fields("EmailAd")
  51.         .txtUdept = rst.Fields("UDept")
  52.     End With
  53.  
  54.  
  55.     rst.Close
  56.  
  57. Exit_cmdOk_Click:
  58.     Exit Sub
  59.  
  60. Err_cmdOk_Click:
  61.     MsgBox err.Description
  62.     Resume Exit_cmdOk_Click
  63.  
  64. End Sub
On the same form where that code resides there is a cancel button with the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCancel_Click()
  2. On Error GoTo Err_cmdCancel_Click
  3.  
  4.     Dim intResponse As Integer
  5.  
  6.     Forms!frmUserLogon.Visible = False
  7.  
  8.     intResponse = MsgBox("Warning:  By canceling, you are about to completely exit the database." & Chr(13) & _
  9.     "Are you sure you want to do this?", vbYesNo + vbExclamation, "Exiting Database")
  10.  
  11.     Select Case intResponse
  12.         Case vbYes
  13.  
  14.             DoCmd.Quit
  15.         Case Else
  16.             Forms!frmUserLogon.Visible = True
  17.     End Select
  18.  
  19. Exit_cmdCancel_Click:
  20.     Exit Sub
  21.  
  22. Err_cmdCancel_Click:
  23.     MsgBox err.Description
  24.     Resume Exit_cmdCancel_Click
  25.  
  26. End Sub
The behaviour that is strange is that if no user information is present and I click cancel, the database closes as it should.

However, If I enter valid user information within the username/password text boxes and click cancel... I get logged in.

Can anyone explain why this is happening? I cant for the life of me see how the Login and Cancel button can be linked here =|

Regards,

Chris
Jul 27 '10 #1
0 1245

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: MB | last post by:
Hi, I am doing a project which uses asp.net to develop its forms. The form uses validation web controls to validate the data entered in text boxes. When Cancel Button is pressed which is to exit...
14
by: clintonG | last post by:
This is an appeal for peer support sent to Microsoft as will be noted in closing. The Login control does not include a Cancel button. The only option is to convert the Login control to a...
1
by: holysmokes99 | last post by:
I am trying to implement a cancel button on my application that ingests a bunch of data from a text file into a database. I have not worked too much with threads, so I am having some trouble. I had...
0
by: Stuart Whiteford | last post by:
Hi, I've got a basic web form, two textboxes, a couple of radio button groups, some required field validators, and a Submit and Cancel button. When the page loads, if I click the Cancel...
1
by: Matthew | last post by:
I have a popup "Property" form that I want to be used as a dialog box. I want the user to be able to cancel their addition of the property wtihout closing the form. .Net however automatically...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
1
by: Sergey Zuyev | last post by:
Hello all I have simple edit form. When user saves data that contains restricted characters such as (< , etc.) , regular expression validator will display a warning message. It all works fine,...
4
by: martin | last post by:
Hello, Is there a way to make a kind of "cancel" button on a form? Suppose you accidently changed or overwrote some data in a form, then I'd like to leave this form at once and cancel any...
4
by: MaxMax | last post by:
I have a dialog box with a Cancel button that I want to be activable with the ESC key. In the form the Cancel button is connected to the CancelButton property. Now my problem is that the OnClick...
5
by: ghjk | last post by:
I have "cancel" button in php files. I want to write common javascript function for cancel button. When user click cancel button I want to clear php form data. Is it possible? <input id="Cancel"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.