I'm working on access database 2007 using VB. i've created a form called "login". PFB the coding:
Private Sub cb_Logon_Click() On Error GoTo Err_Check Dim msg Dim qdfTemp As QueryDef Dim rstTemp As Recordset Dim dbs_tool As Database Dim errstored As Error Dim tv_userid, tv_password, tv_dsname, db_connection As String tv_userid = userid tv_password = password tv_dsname = dsname If Trim(tv_userid) = "" Or IsNull(tv_userid) Then MsgBox "Please enter a valid UserId." Exit Sub End If If Trim(tv_password) = "" Or IsNull(tv_password) Then MsgBox "Please enter a valid Password for the UserId in use." Exit Sub End If If Trim(tv_dsname) = "" Or IsNull(tv_dsname) Then MsgBox "Please enter a valid dsname." Exit Sub End If DoCmd.Hourglass True db_connection = "ODBC;DSN=" & tv_dsname & ";UID=" & tv_userid & ";PWD=" & tv_password & ";" Set dbs_tool = OpenDatabase(tv_dsname, True, True, db_connection) On Error GoTo Err_Check 'DoCmd.OpenForm ("SELECT_FORM") MsgBox "logon success" Set qdfTemp = dbs_tool.CreateQueryDef("") qdfTemp.SQL = "select date" ConnectionTimeout = 1 dbs_tool.Close Start = Timer Do ' This loop pauses a second ' to allow a time-out 'FreeLocks ' Tell Microsoft Access ' engine that program is idle. DoEvents ' Tell Windows to do any ' pending events. Loop While Timer <= Start + 1 'Exit Sub Exit_Step: DoCmd.Hourglass False Exit Sub Err_Check: MsgBox "Authentication failed. Kindly verify your UserID/Password/Data Source Name." GoTo Exit_Step End Sub.
the problem here is when i enter the first time with wrong id or pw, it shows "authentication failed" message. but if i login with correct id and password once and if i try with wrong id or pw successively, it doesn't throw any error. instead it logs in again and the "login success" message is displayed. It throws error , only when the code is reset manually and logged in again.
I'm not sure if the previous parameters are stored in any buffer or database is not closed properly or the ODBC will not be opened in successive attempts?please give me a solution to rectify this problem.