0 Replies - 1366 Views - Last Post: 15 January 2010 - 02:45 AM Rate Topic: -----

#1 aruljoseph   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-January 10

ODBC connection issues in Access database 2007(using VB)

Posted 15 January 2010 - 02:45 AM


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
  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
	DoCmd.Hourglass False
	Exit Sub
	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.


Is This A Good Question/Topic? 0
  • +

Page 1 of 1