473,566 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Closing a database without leaving

Hi
Using access 2003

I have a front end and back end. I would like to close the connection to the
backend so that I can compact the back end without leaving the front end.
Currently I must exit the datbase and start the repair form from another mdb
that is not connected to the back end.

I have tried
Dim appAccess As Access.Applicat ion
appAccess.Close CurrentDatabase

this gives me an error.

any suggestions
Thanks Alfred
Nov 13 '05 #1
2 2744
You must close any tables that are linked to the backend. That is
sufficient for *you* to disconnect from the backend. Other users of
the backend must be out of the database, too.

I use this function to compact the database (watch for word-wrap), and
watch for application-specific calls to local forms.
Public Sub RunCompact(sFil ePathToCompact As String)
' to compact any MDB file

Dim WorkDir As String
Dim CurrentDatabase Name As String
Dim TargetDatabaseN ame As String
Dim i As Integer
Dim iCount As Integer

' define working directory
i = LastBackslash(s FilePathToCompa ct)

WorkDir = Left$(sFilePath ToCompact, i)
CurrentDatabase Name = Mid$(sFilePathT oCompact, i + 1)
TargetDatabaseN ame = CurrentDatabase Name & ".compact"

' Check if destination database already exists
If Dir(WorkDir & TargetDatabaseN ame) <> "" Then
If MsgBox("Destina tion database " & WorkDir &
TargetDatabaseN ame & " already exists, do you want to delete it?",
vbYesNo, "Confirm") = vbYes Then
Kill WorkDir & TargetDatabaseN ame
Else
MsgBox "Compact procedure exiting"
Exit Sub
End If
End If
' close the main form so that no tables are open
On Error Resume Next
DoCmd.Close acForm, "@frmMain"

' Compact database
DBEngine.Compac tDatabase WorkDir & CurrentDatabase Name, WorkDir &
TargetDatabaseN ame
If Err = 0 Then
' remove old database
Kill WorkDir & CurrentDatabase Name
Name WorkDir & TargetDatabaseN ame As WorkDir &
CurrentDatabase Name
Else
MsgBox "Compacting operation failed, couldn't create new
database file " & WorkDir & TargetDatabaseN ame & vbCrLf & vbCrLf & _
"Nothing has been damaged. Suggest that you exit completely
from LODM then try again. Ensure that nobody else is using the
database." & vbCrLf & vbCrLf & _
"WARNING!! If you have just completed a Restore from
Archive, it is CRITICAL that the backend be " & _
"compacted before adding any new trips. Without compacting,
the TripID sequence will become corrupted.", vbCritical

End If

End Sub

On Fri, 3 Dec 2004 16:10:09 -0000, "ALFRED" <AD*@SPAM.CO.ZA > wrote:
Hi
Using access 2003

I have a front end and back end. I would like to close the connection to the
backend so that I can compact the back end without leaving the front end.
Currently I must exit the datbase and start the repair form from another mdb
that is not connected to the back end.

I have tried
Dim appAccess As Access.Applicat ion
appAccess.Close CurrentDatabase

this gives me an error.

any suggestions
Thanks Alfred

*************** *******
ja************* *@telusTELUS.ne t
remove uppercase letters for true email
http://www.geocities.com/jacksonmacd/ for info on MS Access security
Nov 13 '05 #2
Thanks
I will try it
Alfred
"Jack MacDonald" <ja************ **@telus.net> wrote in message
news:uf******** *************** *********@4ax.c om...
You must close any tables that are linked to the backend. That is
sufficient for *you* to disconnect from the backend. Other users of
the backend must be out of the database, too.

I use this function to compact the database (watch for word-wrap), and
watch for application-specific calls to local forms.
Public Sub RunCompact(sFil ePathToCompact As String)
' to compact any MDB file

Dim WorkDir As String
Dim CurrentDatabase Name As String
Dim TargetDatabaseN ame As String
Dim i As Integer
Dim iCount As Integer

' define working directory
i = LastBackslash(s FilePathToCompa ct)

WorkDir = Left$(sFilePath ToCompact, i)
CurrentDatabase Name = Mid$(sFilePathT oCompact, i + 1)
TargetDatabaseN ame = CurrentDatabase Name & ".compact"

' Check if destination database already exists
If Dir(WorkDir & TargetDatabaseN ame) <> "" Then
If MsgBox("Destina tion database " & WorkDir &
TargetDatabaseN ame & " already exists, do you want to delete it?",
vbYesNo, "Confirm") = vbYes Then
Kill WorkDir & TargetDatabaseN ame
Else
MsgBox "Compact procedure exiting"
Exit Sub
End If
End If
' close the main form so that no tables are open
On Error Resume Next
DoCmd.Close acForm, "@frmMain"

' Compact database
DBEngine.Compac tDatabase WorkDir & CurrentDatabase Name, WorkDir &
TargetDatabaseN ame
If Err = 0 Then
' remove old database
Kill WorkDir & CurrentDatabase Name
Name WorkDir & TargetDatabaseN ame As WorkDir &
CurrentDatabase Name
Else
MsgBox "Compacting operation failed, couldn't create new
database file " & WorkDir & TargetDatabaseN ame & vbCrLf & vbCrLf & _
"Nothing has been damaged. Suggest that you exit completely
from LODM then try again. Ensure that nobody else is using the
database." & vbCrLf & vbCrLf & _
"WARNING!! If you have just completed a Restore from
Archive, it is CRITICAL that the backend be " & _
"compacted before adding any new trips. Without compacting,
the TripID sequence will become corrupted.", vbCritical

End If

End Sub

On Fri, 3 Dec 2004 16:10:09 -0000, "ALFRED" <AD*@SPAM.CO.ZA > wrote:
Hi
Using access 2003

I have a front end and back end. I would like to close the connection to
the
backend so that I can compact the back end without leaving the front end.
Currently I must exit the datbase and start the repair form from another
mdb
that is not connected to the back end.

I have tried
Dim appAccess As Access.Applicat ion
appAccess.Close CurrentDatabase

this gives me an error.

any suggestions
Thanks Alfred

*************** *******
ja************* *@telusTELUS.ne t
remove uppercase letters for true email
http://www.geocities.com/jacksonmacd/ for info on MS Access security

Nov 13 '05 #3

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

Similar topics

6
11401
by: MAB71 | last post by:
There should be a way to copy an access database ( .mdb file ) without closing connections to it. Unfortunately the FileCopy statement in VB gives an error if users are connected to the db. But I can copy the file using windows explorer so there must be a way. WinAPI function or something? I'm using VB6 and Access 2000
5
3035
by: nick_faye | last post by:
Hi, I am still a newbie to VB and using MS Access 2000. I am currently trying to provide a preview of reports before printing them. My program is simple: AC.DoCmd.OpenReport "MyReport", acViewPreview AC.Visible = True AC.DoCmd.ShowToolbar "Print Preview", acToolbarNo AC.DoCmd.ShowToolbar "Menu Bar", acToolbarNo
1
1298
by: csharpbeginner | last post by:
My requirement is a certain database connection should be closed only when the object is unloaded from memory. Is the class destructor a good place to close open database connections? Thanks in advance for your reply.
1
2559
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and close them as early as possible. My requirement is as follows: I'm developing a class library that will be instantiated by a COM component. My class...
1
1511
by: Vegar Hansen | last post by:
Hello everone. Can somebody help me? When I run my code I can read, write to and delete from database, but when I have done one of these things and try to copy the databasefile from my folder to an other folder with Windows Explorer the system "hangs up" for a couple of minutes. It seems like the databasefile is not closed. But after 2 - 3...
1
3077
by: LeAnne | last post by:
my application polls a database every X seconds. Some times X = 0.5 seconds (500 milli seconds) The way the code has been written, the SQL connection is opened & closed during every poll. Is this effecient? Should i be leaving the connection opened & then polling the database every 500 milli seconds? Or will the connection be simply...
3
6279
by: Finn Stampe Mikkelsen | last post by:
Hi I have defined a table in my database, with 2 date-fields. I have set a default value to DBNull. I have integrated a nullable datetimepicker control to my project and set the apropriate NullValue in my datagridview... Everything works great, with a table-row added manually to the database, without setting any value to the second...
1
1623
by: =?Utf-8?B?Q2hyaXNB?= | last post by:
Two questions: 1. I have several asp.net pages that initiate a file download, via Response.WriteFile(). This works fine, except that it leaves the original page up. These pages are generally launched in new windows, so I'd prefer that they go away by themselves. Can anyone suggest a way to have the page close by itself? 2. I have tried...
8
4145
by: Wayne | last post by:
I have had a problem for some time with several databases and figure there must be a common underlying cause. Sometimes when I open a database, nothing appears to happen, but an .ldb file gets created and Access is running in Task Manager. No sign of Access on the screen or Taskbar though. Today, I've partly figured out what is happening....
0
7666
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...
0
7584
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...
0
7888
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. ...
0
8108
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...
1
7644
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...
0
7951
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...
0
6260
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.