Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 27th, 2009, 05:49 AM
JezLisle JezLisle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Manchester
Posts: 7 JezLisle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 6 sec
Reputation Power: 0
Execute Stored Proc through AccessVBA

I have this code below which will run a Stored Procedure and works great, until the incorrect Username or Password is input.

Then I get an error

"Operation is not allowed when the object is closed"

This debugs on line -
Quote:
If rs.BOF And rs.EOF Then


What should I do when there is a wrong Username or Password input incorrectly?

Code:
Private Sub lblLogIn_Click()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
'*************************************************  ************************************
    If IsNull(Me.txtUsername) Or Me.txtUsername = "" Then
        MsgBox "You must enter a Username.", vbCritical, cApplicationName & " - Required Data"
        Me.txtUsername.SetFocus
        Exit Sub
    End If
'*************************************************  ************************************
    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
        MsgBox "You must enter a Password.", vbCritical, cApplicationName & " - Required Data"
        Me.txtPassword.SetFocus
        Exit Sub
    End If
'*************************************************  ************************************
    Set cnn = New ADODB.Connection
    Set cmd = New ADODB.Command
    cnn.Open cCnnStr
    cnn.CursorLocation = adUseClient
    cmd.ActiveConnection = cnn
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "sp_CIP_LogIn"
    cmd.Parameters.Append cmd.CreateParameter("@pUserLogIn", adVarChar, adParamInput, 100, txtUsername.Value)
    cmd.Parameters.Append cmd.CreateParameter("@pPassword", adVarChar, adParamInput, 25, txtPassword.Value)
    Set rs = cmd.Execute
'*************************************************  ************************************
    If rs.BOF And rs.EOF Then
        MsgBox "Nothing"
        Else
        MsgBox Me.txtUsername & " " & Me.txtPassword
    End If
    rs.Close
    Set rs = Nothing
    cnn.Close
    Set cnn = Nothing
    Set cmd = Nothing
    DoCmd.Close acForm, "frmLogIn", acSaveNo
    DoCmd.OpenForm "frmSplash"
End Sub

Reply With Quote
  #2  
Old July 27th, 2009, 04:19 PM
AlanSidman's Avatar
AlanSidman AlanSidman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Location: Lake County, IL
Posts: 172 AlanSidman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 6 h 23 m 22 sec
Reputation Power: 2
Why not put in an error message telling the user that the input was incorrect, resubmit and reprocess.

Alan
__________________
Alan Sidman
__________
If I helped you, I'd like to know. Click on the icon next to the thread number and tell me.

Reply With Quote
  #3  
Old July 28th, 2009, 02:07 AM
JezLisle JezLisle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Manchester
Posts: 7 JezLisle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 6 sec
Reputation Power: 0
Quote:
Originally Posted by AlanSidman
Why not put in an error message telling the user that the input was incorrect, resubmit and reprocess.

Alan

I was thinking that but where would I put this, as am unsure where to put it?

Reply With Quote
  #4  
Old July 28th, 2009, 05:49 AM
AlanSidman's Avatar
AlanSidman AlanSidman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Location: Lake County, IL
Posts: 172 AlanSidman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 6 h 23 m 22 sec
Reputation Power: 2
Just before your If IsNull statements, put an error handler that tells Access what to do in the event of an error. Put your error vba that the error handler points to at the end of the function.

Here is an example
http://allenbrowne.com/ser-23b.html

HTH
Alan

Reply With Quote
  #5  
Old July 28th, 2009, 08:11 AM
JezLisle JezLisle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Manchester
Posts: 7 JezLisle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 6 sec
Reputation Power: 0
Ok, this below is what I have done...

When I try compile it I get an error "Label Not Defined" this is on the line On Error GoTo Err_Retry highlighting Err_Retry

Where have I gone wrong?

Code:
Private Sub lblLogIn_Click()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
'*************************************************  ************************************
On Error GoTo Err_Retry
	If IsNull(Me.txtUsername) Or Me.txtUsername = "" Then
		MsgBox "You must enter a Username.", vbCritical, cApplicationName & " - Required Data"
		Me.txtUsername.SetFocus
		Exit Sub
	End If
'*************************************************  ************************************
	If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
		MsgBox "You must enter a Password.", vbCritical, cApplicationName & " - Required Data"
		Me.txtPassword.SetFocus
		Exit Sub
	End If
'*************************************************  ************************************
	Set cnn = New ADODB.Connection
	Set cmd = New ADODB.Command
	cnn.Open cCnnStr
	cnn.CursorLocation = adUseClient
	cmd.ActiveConnection = cnn
	cmd.CommandType = adCmdStoredProc
	cmd.CommandText = "sp_CIP_LogIn"
	cmd.Parameters.Append cmd.CreateParameter("@pUserLogIn", adVarChar, adParamInput, 100, txtUsername.Value)
	cmd.Parameters.Append cmd.CreateParameter("@pPassword", adVarChar, adParamInput, 25, txtPassword.Value)
	Set rs = cmd.Execute
'*************************************************  ************************************
	If rs.BOF And rs.EOF Then
		MsgBox "Nothing"
		Else
		MsgBox Me.txtUsername & " - " & Me.txtPassword
	End If
	rs.Close
	Set rs = Nothing
	cnn.Close
	Set cnn = Nothing
	Set cmd = Nothing
	DoCmd.Close acForm, "frmLogIn", acSaveNo
	DoCmd.OpenForm "frmSplash"
Exit_Retry:
	Exit Sub
	End Sub
Err_Retry:
	MsgBox "Password Invalid. Please Try Again", vbExclamation, cApplicationName & " - Invalid Entry!"
	Me.txtDummy.SetFocus
	Exit Sub
	intLogInAttempts = intLogInAttempts + 1
	If intLogInAttempts > 3 Then
		MsgBox "You do not have access to this database. Please contact the System Administrator.", vbCritical, cApplicationName & " - Restricted Access!"
		Application.Quit
		Exit Sub
	End If
End Sub

Reply With Quote
  #6  
Old July 29th, 2009, 02:43 PM
JezLisle JezLisle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Manchester
Posts: 7 JezLisle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 6 sec
Reputation Power: 0
Where have I gone wrong with the Error trapping code?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Execute Stored Proc through AccessVBA


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek