473,748 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems When Connecting and Disconnecting to an Access Database in VB6!! HELP PLEASE!!

Hello,

I'm having trouble with a little programme of mine where I connect to
an access database. It seems to connect fine, and disconnect fine, but
then after it won't reconnect, I get the error "operation is not
allowed when object is open" so I take out the line of code:

BookDetails.Con nection1.Open

and it comes up with the error "operation is not allowed when object
is closed"

I put my hands up to the fact that I'm not an expert at this (as you
may see in the code!!) so I could quite possibly be using the wrong
code!!! But this is becoming quite frustrating now coz I can't seem to
find any help anywhere!!!

The programme is for entering details of books into an Access database
by using a more user friendly GUI created with VB6!

The code below is from two forms one for entering the book details and
one for a main menu. The problem occurs quite often in the programme,
but if I can get some help with this problem then I can use what I've
learnt to correct the other problems!! The example I'm going to give
is for the fill forms button and delete records button.

When you load the programme you get the main menu where you click to
go to the books form then you click the fill forms button and type the
reference number and then the amount of records. This fills all the
refs so you don't have to type them in manually, this works fine! then
when you click the close button and go back to the main menu and click
the delete records button it deletes all the records (up to this point
all is well) then when you go back into the books form and click the
fill refs button again that's when you get the error I stated above!
What am I doing wrong???

The Code:

On frmBooks:

Private Sub cmdFillForms_Cl ick()
On Error GoTo err
MsgBox "PLEASE NOTE: You MUST clear out all previous books to use
this function and the Ref. No. fields should be empty."

Dim CurrentRef, NumberRecords, NumberCount As Integer
NumberCount = 0
CurrentRef = InputBox("Pleas e enter your first reference number.")
If CurrentRef = "" Then
MsgBox "Sorry the number you entered is invalid! Please try
again.", vbExclamation
Exit Sub
Else
NumberRecords = InputBox("Pleas e enter the amount of reference
numbers to be added.")

frmPleaseWait.S how
For i = 0 To 20
DoEvents
Next i
Do While NumberCount <= NumberRecords - 1

BookDetails.rst blBooks.AddNew
txtRef.Text = CurrentRef
NumberCount = NumberCount + 1
CurrentRef = CurrentRef + 1
Loop
BookDetails.rst blBooks.UpdateB atch
Unload frmPleaseWait
BookDetails.rst blBooks.MoveFir st
End If
Exit Sub

err:
MsgBox err.Description
Unload frmPleaseWait
End Sub

On frmMainMenu:

Private Sub cmdClear_Click( )
On Error GoTo err
Dim response
Dim rs As Recordset

response = MsgBox("WARNING ! There is NO way to undo this action
please make sure that you are sure you want to clear your data!", 4 +
48, "WARNING!")
If response = vbNo Then
Exit Sub
End If

response = MsgBox("FINAL WARNING! You are about to delete all
data!! There is no way to undo this action! Are you sure?", 4 + 48,
"FINAL WARNING!")
If response = vbNo Then
Exit Sub
Else
frmPleaseWait.S how
For i = 0 To 20
DoEvents
Next i

BookDetails.com Clear
BookDetails.Con nection1.Close

For i = 0 To 20
DoEvents
Next i
'Now run DB compact routine
Dim JRO As JRO.JetEngine
Set JRO = New JRO.JetEngine
JRO.CompactData base "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=c:\IB\IB ook.mdb", _
"Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=c:\IB\IB ook1.mdb;Jet OLEDB:Engine Type=4"

Kill ("c:\IB\IBook.m db")
Name "c:\IB\IBook1.m db" As "c:\IB\IBook.md b"
Set JRO = Nothing
Unload frmPleaseWait
MsgBox ("All data has been deleted!")
BookDetails.Con nection1.Open
BookDetails.rst blBooks.Open

End If
Exit Sub
err:
Unload frmPleaseWait
MsgBox err.Description
MsgBox "PLEASE NOTE: YOUR DATABASE HAS NOT BEEN CLEARED!"
End Sub

Any help you can give would be greatly appreciated!!

Thanks,

Ben
Nov 20 '05 #1
13 4334
"Joner" <be*********@ho tmail.com> schrieb
I'm having trouble with a little programme of mine where I connect
to an access database. It seems to connect fine, and disconnect fine,
but then after it won't reconnect, I get the error "operation is
not allowed when object is open" so I take out the line of code:


This group (micrsoft.publi c.dotnet.langua ges.vb) is about VB.NET ("dotnet",
see group name). Older VB versions are handled at one of the
microsoft.publi c.vb.* groups.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
* be*********@hot mail.com (Joner) scripsit:
[...]

This is a VB.NET language group. You may want to turn to one of the
microsoft.publi c.vb.data.* groups.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Heh heh.

What seems to be happening is this:

In your original, you might not have been disconnecting properly
(Connection.Clo se), which meant that when you tried to reconnect you got the
"operation is not allowed when object is open" error. Then you took out the
"Connection.Ope n" method, and something else (I'm guessing a recordset
operation or similar) is complaining that the connection closed.

The long and the short of it is to put the "Connection1.Op en" back in, and
find out why the disconnect doesn't work properly.

Hope this helps,

Sparky.
"Joner" <be*********@ho tmail.com> wrote in message
news:43******** *************** ***@posting.goo gle.com...
Hello,

I'm having trouble with a little programme of mine where I connect to
an access database. It seems to connect fine, and disconnect fine, but
then after it won't reconnect, I get the error "operation is not
allowed when object is open" so I take out the line of code:

BookDetails.Con nection1.Open

and it comes up with the error "operation is not allowed when object
is closed"

I put my hands up to the fact that I'm not an expert at this (as you
may see in the code!!) so I could quite possibly be using the wrong
code!!! But this is becoming quite frustrating now coz I can't seem to
find any help anywhere!!!

The programme is for entering details of books into an Access database
by using a more user friendly GUI created with VB6!

The code below is from two forms one for entering the book details and
one for a main menu. The problem occurs quite often in the programme,
but if I can get some help with this problem then I can use what I've
learnt to correct the other problems!! The example I'm going to give
is for the fill forms button and delete records button.

When you load the programme you get the main menu where you click to
go to the books form then you click the fill forms button and type the
reference number and then the amount of records. This fills all the
refs so you don't have to type them in manually, this works fine! then
when you click the close button and go back to the main menu and click
the delete records button it deletes all the records (up to this point
all is well) then when you go back into the books form and click the
fill refs button again that's when you get the error I stated above!
What am I doing wrong???

The Code:

On frmBooks:

Private Sub cmdFillForms_Cl ick()
On Error GoTo err
MsgBox "PLEASE NOTE: You MUST clear out all previous books to use
this function and the Ref. No. fields should be empty."

Dim CurrentRef, NumberRecords, NumberCount As Integer
NumberCount = 0
CurrentRef = InputBox("Pleas e enter your first reference number.")
If CurrentRef = "" Then
MsgBox "Sorry the number you entered is invalid! Please try
again.", vbExclamation
Exit Sub
Else
NumberRecords = InputBox("Pleas e enter the amount of reference
numbers to be added.")

frmPleaseWait.S how
For i = 0 To 20
DoEvents
Next i
Do While NumberCount <= NumberRecords - 1

BookDetails.rst blBooks.AddNew
txtRef.Text = CurrentRef
NumberCount = NumberCount + 1
CurrentRef = CurrentRef + 1
Loop
BookDetails.rst blBooks.UpdateB atch
Unload frmPleaseWait
BookDetails.rst blBooks.MoveFir st
End If
Exit Sub

err:
MsgBox err.Description
Unload frmPleaseWait
End Sub

On frmMainMenu:

Private Sub cmdClear_Click( )
On Error GoTo err
Dim response
Dim rs As Recordset

response = MsgBox("WARNING ! There is NO way to undo this action
please make sure that you are sure you want to clear your data!", 4 +
48, "WARNING!")
If response = vbNo Then
Exit Sub
End If

response = MsgBox("FINAL WARNING! You are about to delete all
data!! There is no way to undo this action! Are you sure?", 4 + 48,
"FINAL WARNING!")
If response = vbNo Then
Exit Sub
Else
frmPleaseWait.S how
For i = 0 To 20
DoEvents
Next i

BookDetails.com Clear
BookDetails.Con nection1.Close

For i = 0 To 20
DoEvents
Next i
'Now run DB compact routine
Dim JRO As JRO.JetEngine
Set JRO = New JRO.JetEngine
JRO.CompactData base "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=c:\IB\IB ook.mdb", _
"Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=c:\IB\IB ook1.mdb;Jet OLEDB:Engine Type=4"

Kill ("c:\IB\IBook.m db")
Name "c:\IB\IBook1.m db" As "c:\IB\IBook.md b"
Set JRO = Nothing
Unload frmPleaseWait
MsgBox ("All data has been deleted!")
BookDetails.Con nection1.Open
BookDetails.rst blBooks.Open

End If
Exit Sub
err:
Unload frmPleaseWait
MsgBox err.Description
MsgBox "PLEASE NOTE: YOUR DATABASE HAS NOT BEEN CLEARED!"
End Sub

Any help you can give would be greatly appreciated!!

Thanks,

Ben

Nov 20 '05 #4
Thanks for the help Spark but i already knew that, the problem is cant
seem to get the bugger to dissconnect and the file is still open!!!

Can anybody eles help me!! :(

"Sparky" <ne**********@h otmail.com> wrote in message news:<bu******* ***@newsg3.svr. pol.co.uk>...
Heh heh.

What seems to be happening is this:

In your original, you might not have been disconnecting properly
(Connection.Clo se), which meant that when you tried to reconnect you got the
"operation is not allowed when object is open" error. Then you took out the
"Connection.Ope n" method, and something else (I'm guessing a recordset
operation or similar) is complaining that the connection closed.

The long and the short of it is to put the "Connection1.Op en" back in, and
find out why the disconnect doesn't work properly.

Hope this helps,

Sparky.

Nov 20 '05 #5
Why are you posting to a .NET group?
Nov 20 '05 #6
On Thu, 15 Jan 2004 06:52:11 -0600, "scorpion53 061" <Its the end of
the world as we know it@here.com> wrote:
Why are you posting to a .NET group?

It's a payback for all the .Net questions we get here, on CLVBM. ;-)

--

Regards, Frank
Nov 20 '05 #7
So you're saying that even calling Connection.Clos e doesn't close the
connection? Just a guess, but does setting the connection object to nothing
after disconnecting help at all?

Sparky.

"Joner" <be*********@ho tmail.com> wrote in message
news:43******** *************** ***@posting.goo gle.com...
Thanks for the help Spark but i already knew that, the problem is cant
seem to get the bugger to dissconnect and the file is still open!!!

Can anybody eles help me!! :(

"Sparky" <ne**********@h otmail.com> wrote in message

news:<bu******* ***@newsg3.svr. pol.co.uk>...
Heh heh.

What seems to be happening is this:

In your original, you might not have been disconnecting properly
(Connection.Clo se), which meant that when you tried to reconnect you got the "operation is not allowed when object is open" error. Then you took out the "Connection.Ope n" method, and something else (I'm guessing a recordset
operation or similar) is complaining that the connection closed.

The long and the short of it is to put the "Connection1.Op en" back in, and find out why the disconnect doesn't work properly.

Hope this helps,

Sparky.

Nov 20 '05 #8
Nah sorry mate didn't help I had tried that before but it didn't work
then either, i just tried it agin but not surprisingly... nope!!

This snip of code:

Kill ("C:\Program Files\IBook Outworker\ibook .mdb")
Name "C:\Program Files\IBook Outworker\ibook 1.mdb" As
"C:\Program Files\IBook Outworker\ibook .mdb"
Set JRO = Nothing
Unload frmPleaseWait
MsgBox ("All data has been deleted!")
BookDetails.Con nection1.Open
'BookDetails.rs tblBooks.Open

if you run the code with the last line not commented out, then it
works the first time but when you run it again you get this error
(below)!! so many errors grrrr!!

Run-time error '3709':
the connection cannot be used to perform this operation. It is either
closed or invalid in this context

im starting to lose hope! any other ideas spark?

Thanks
Joner
"Sparky" <ne**********@h otmail.com> wrote in message news:<bu******* ***@news5.svr.p ol.co.uk>...
So you're saying that even calling Connection.Clos e doesn't close the
connection? Just a guess, but does setting the connection object to nothing
after disconnecting help at all?

Sparky.

Nov 20 '05 #9
After you call connection.clos e, does the lockfile (ldb) disappear, or is it
still there?

Sparky.

"Joner" <be*********@ho tmail.com> wrote in message
news:43******** *************** ***@posting.goo gle.com...
Nah sorry mate didn't help I had tried that before but it didn't work
then either, i just tried it agin but not surprisingly... nope!!

This snip of code:

Kill ("C:\Program Files\IBook Outworker\ibook .mdb")
Name "C:\Program Files\IBook Outworker\ibook 1.mdb" As
"C:\Program Files\IBook Outworker\ibook .mdb"
Set JRO = Nothing
Unload frmPleaseWait
MsgBox ("All data has been deleted!")
BookDetails.Con nection1.Open
'BookDetails.rs tblBooks.Open

if you run the code with the last line not commented out, then it
works the first time but when you run it again you get this error
(below)!! so many errors grrrr!!

Run-time error '3709':
the connection cannot be used to perform this operation. It is either
closed or invalid in this context

im starting to lose hope! any other ideas spark?

Thanks
Joner
"Sparky" <ne**********@h otmail.com> wrote in message

news:<bu******* ***@news5.svr.p ol.co.uk>...
So you're saying that even calling Connection.Clos e doesn't close the
connection? Just a guess, but does setting the connection object to nothing after disconnecting help at all?

Sparky.

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1854
by: Sérgio Almeida | last post by:
Greetings I'm having problems adding records to an access database. What I want to do is very simple. Here is my code. __CODE_START__ dim sqlStatement sqlStatement="insert into Records(artist,album,format,label,tracks,year) values ('Pink Floyd','THE WALL','2CD','EMI',99,1979)"
0
1702
by: Asim | last post by:
I seem to be having a lot of problems with running/developing web site on my XP Professional OS. I have a simple web site (using ASP/VB), which retrieves information from an Access 2000 database. I have MS Access XP installed on my machine. When I open the database in Access and try to open up a page, I get this error: Microsoft OLE DB Provider for ODBC Drivers error '80004005' Could not use '(unknown)'; file
1
1561
by: andrew.newell | last post by:
Hi, I use MS Access to connect to and SQL Database this has been working fine until recently. Whenever I add a new record (post record 723) it does not allow me to change it. My DBA has checked in the SQL server and the record is not locked it seems that it is only locked when connecting through Access. Does anybody have any ideas?
1
3487
by: Tom Wild | last post by:
Hi I am trying to create a webform that connects to an Access database. If I use the connection string: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Gizmo\Gizmo.mdb" Then the application connects to the database and downloads data fine but when I try to fire an Update command I get the following error: "Problem firing System.Data.OleDb.OleDbCommand - Operation must use an updateable query"
9
2199
by: Nathan Sokalski | last post by:
I am trying to connect to a Microsoft Access Database from my ASP.NET Application. I use the following code to create my connection string: cmdSelect.Connection = New System.Data.OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATASOURCE=" & Server.MapPath("/WebApplication1/nathansokalski_com.mdb")) Although the error does not occur until the Fill() method is called:
11
2048
by: CM Manager via DotNetMonster.com | last post by:
I am very frustrated due to this exception error I am receiving. I've tried searching numerous user support groups, Microsoft Support Net, Google, etc. and haven't found exactly my situation. Hopefully someone here can help. I am just learning VB.NET and purchased the SAM's "Teach Yourself VB.NET 2003 in 21 days' book. I am trying to connect to an Access database I created locally on my computer per Chapter 16. I originally had it on a...
0
1158
by: Rex | last post by:
Hi I am getting this error message "Cannot start your application. The workgroup information file is missing or opened exclusively by another user." when I am trying to connect to access database. I want to get the names of the customer from a database table for mail merge. I dont have any other user using the same database. Also what is workgroup information file.
3
1641
by: firozfasilan | last post by:
pCnString = "Data Source=" & App.Path & "\database\WO.mdb;Provider=Microsoft.jet.oledb.4.0; uID=sa;Pwd=subhanalla" i am used the above code for providing a password to access database when i am try to open it , it gives a error message and i can't open the access data base . please help me the error is "could not find the installable ISAM"
0
1451
by: pawera | last post by:
Hi Everybody ! I`ve got a problem with developing application which is to be run on PDA (MIO A701 with WIndows Mobile 5). I`m trying to create application in Visual Basic NET using NET Compact Framework. This will be very simple database application using Access Database. Unfortunatelly I can`t use class OleDbConnection and app is not able to connect with my mdb.
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.