473,413 Members | 1,727 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,413 software developers and data experts.

can anyone help me out with the error operation not allowed wen object is open

If i close the recordset then it automatically gets focussed to the login..can any1 help me out in rectifyin the code given below-
Expand|Select|Wrap|Line Numbers
  1. Dim rs As New ADODB.Recordset
  2. Dim cn As New ADODB.Connection
  3. Private Sub Command1_Click()
  4. If Text1 = "" Then
  5. MsgBox "enter the username", vbInformation + vbOKOnly, "login"
  6. Text1.SetFocus
  7. Exit Sub
  8. End If
  9. If Text2 = "" Then
  10. MsgBox "enter the password", vbInformation + vbOKOnly, "login"
  11. Text2.SetFocus
  12. Exit Sub
  13. End If
  14. If Text1 <> "" And Text2 <> "" Then
  15. If rs.State = 1 Then
  16. rs.Close
  17. Else
  18. rs.Open "select * from login where username='" & Text1 & "' and password='" & Text2 & "'", cn, adOpenDynamic, adLockOptimistic, adCmdText
  19. If rs.EOF = True Then
  20. MsgBox "invalid username and pass", vbCritical + vbOKOnly, "login"
  21. Text1 = ""
  22. Text2 = ""
  23. Text1.SetFocus
  24. Else
  25. MsgBox "username and pass corect", vbInformation + vbOKOnly, "login"
  26. If vbOK Then
  27. Unload Me
  28. MDIForm1.Show
  29. End If
  30. End If
  31. End If
  32. End If
  33. End Sub
  34.  
  35. Private Sub Command2_Click()
  36. Unload Me
  37. End Sub
  38.  
  39. Private Sub Form_Load()
  40. Text1 = ""
  41. Text2 = ""
  42. cn.Open "Provider=MSDAORA.1;Password=tiger;User ID=system;Persist Security Info=True"
  43. End Sub
Attached Images
File Type: jpg untitled.jpg (51.3 KB, 108 views)
Oct 16 '13 #1
4 1322
MikeTheBike
639 Expert 512MB
Hi

I suggest this mod
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     If Text1 = "" Then
  3.         MsgBox "enter the username", vbInformation + vbOKOnly, "login"
  4.         Text1.SetFocus
  5.         Exit Sub
  6.     End If
  7.     If Text2 = "" Then
  8.         MsgBox "enter the password", vbInformation + vbOKOnly, "login"
  9.         Text2.SetFocus
  10.         Exit Sub
  11.     End If
  12.     If Text1 <> "" And Text2 <> "" Then
  13.         If rs.State = 1 Then
  14.         rs.Close
  15.     Else
  16.         rs.Open "select * from login where username='" & Text1 & "' and password='" & Text2 & "'", cn, adOpenDynamic, adLockOptimistic, adCmdText
  17.         If rs.EOF = True Then
  18.             MsgBox "invalid username and pass", vbCritical + vbOKOnly, "login"
  19.             Text1 = ""
  20.             Text2 = ""
  21.             Text1.SetFocus
  22.         Else
  23.             MsgBox "username and pass corect", vbInformation + vbOKOnly, "login"
  24.             If vbOK Then
  25.                 Unload Me
  26.                 MDIForm1.Show
  27.             End If
  28.         End If
  29.         rs.Close  '########## CLOSE RECORDSET HERE !!
  30.     End If
  31. End Sub
ie add rs.close where indicated on line 29.

Also 'If vbOK Then' is redundant as vbOK is always true !! (ie = 1)

HTH


MTB
Oct 16 '13 #2
well its still the same.I am getting the error pointed at cn.open in the form load...thank u in advance :)
Oct 17 '13 #3
MikeTheBike
639 Expert 512MB
I must confess I am puzzled why a connection should be open in the on load event but you could try this
Expand|Select|Wrap|Line Numbers
  1. If cn.State = adStateClosed Then cn.Open "Provider=MSDAORA.1;Password=tiger;User ID=system;Persist Security Info=True"
However I would change the module level declaration to
Expand|Select|Wrap|Line Numbers
  1. Dim rs As ADODB.Recordset
  2. Dim cn As ADODB.Connection
And the load even to this
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Text1 = ""
  3.     Text2 = ""
  4.  
  5.     Set cn = New ADODB.Connection
  6.     Set rs = New ADODB.Recordset
  7.  
  8.     cn.Open "Provider=MSDAORA.1;Password=tiger;User ID=system;Persist Security Info=True"
  9. End Sub
and, although not strictly necessary in this instance, but just for completeness and good housekeeping(?), add this
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.     If rs.State = adStateOpen Then rs.Close
  3.     Set rs = Nothing
  4.  
  5.     cn.Close
  6.     Set cn = Nothing
  7. End Sub
??

HTH


MTB
Oct 17 '13 #4
thank you anyways i figured the error :D it was actually my timer control enabled for progress bar which was causing all of the mess :)
Oct 21 '13 #5

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

Similar topics

2
by: N. Demos | last post by:
I'm having problems with a custom JS object (XMLLoadObject) I designed to load XML and XSL files, perform an XSL transform with them and embed the resultant HTML fragment into the host HTML...
1
by: celtic_kiwi | last post by:
I have an Access 97 database, quite large, and have started getting the error, Error 3048: Can't Open any more databases. -The data is split from the application (front end and back end). -The...
0
by: J Gao | last post by:
Hi, All, I got this error when trying to compile a web project. The file 'bin\Kennel.dll' cannot be copied to the run directory. The requested operation cannot be performed on a file with a...
0
by: dejanvesic | last post by:
Hello. Windows service is in question, Framework 2.0, operating system is Windows XP Prof. Windows service is accessing file taking turns with ASP.NET application. For synhronisation of...
0
by: dp | last post by:
hello, I have service that copy dll file that contain information of one of the sources of the event viewer. the service is in system permission. if someone used event viewer before the process ,...
2
by: deadlycow21 | last post by:
I am trying to open a open file dialog: Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click OpenFileDialog1.Filter = "*.mp3,...
2
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the...
1
by: sean_walsh | last post by:
Hi From classic ASP, I had a custom error handling situation that was quite simple. Errors were all redirected to Error.asp. This page would check 2 settings, EmailErrorMessage and...
3
by: Frisco Depot | last post by:
I have a Run-time error problem on a Vista computer. There are two computers involved, The first one is Vista Home Premium SP1 with Windows Mail Version 6.0.6000.16386 (vista_rtm.061101-2205)...
0
by: tirupathiraov | last post by:
I have set the prepared statement ResultSet.HOLD_CURSORS_OVER_COMMIT and the same thing working on one instace of DB2 and not working on other instance of DB2. what could be the problem? ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.