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

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.Application
appAccess.CloseCurrentDatabase

this gives me an error.

any suggestions
Thanks Alfred
Nov 13 '05 #1
2 2735
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(sFilePathToCompact As String)
' to compact any MDB file

Dim WorkDir As String
Dim CurrentDatabaseName As String
Dim TargetDatabaseName As String
Dim i As Integer
Dim iCount As Integer

' define working directory
i = LastBackslash(sFilePathToCompact)

WorkDir = Left$(sFilePathToCompact, i)
CurrentDatabaseName = Mid$(sFilePathToCompact, i + 1)
TargetDatabaseName = CurrentDatabaseName & ".compact"

' Check if destination database already exists
If Dir(WorkDir & TargetDatabaseName) <> "" Then
If MsgBox("Destination database " & WorkDir &
TargetDatabaseName & " already exists, do you want to delete it?",
vbYesNo, "Confirm") = vbYes Then
Kill WorkDir & TargetDatabaseName
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.CompactDatabase WorkDir & CurrentDatabaseName, WorkDir &
TargetDatabaseName
If Err = 0 Then
' remove old database
Kill WorkDir & CurrentDatabaseName
Name WorkDir & TargetDatabaseName As WorkDir &
CurrentDatabaseName
Else
MsgBox "Compacting operation failed, couldn't create new
database file " & WorkDir & TargetDatabaseName & 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.Application
appAccess.CloseCurrentDatabase

this gives me an error.

any suggestions
Thanks Alfred

**********************
ja**************@telusTELUS.net
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.com...
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(sFilePathToCompact As String)
' to compact any MDB file

Dim WorkDir As String
Dim CurrentDatabaseName As String
Dim TargetDatabaseName As String
Dim i As Integer
Dim iCount As Integer

' define working directory
i = LastBackslash(sFilePathToCompact)

WorkDir = Left$(sFilePathToCompact, i)
CurrentDatabaseName = Mid$(sFilePathToCompact, i + 1)
TargetDatabaseName = CurrentDatabaseName & ".compact"

' Check if destination database already exists
If Dir(WorkDir & TargetDatabaseName) <> "" Then
If MsgBox("Destination database " & WorkDir &
TargetDatabaseName & " already exists, do you want to delete it?",
vbYesNo, "Confirm") = vbYes Then
Kill WorkDir & TargetDatabaseName
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.CompactDatabase WorkDir & CurrentDatabaseName, WorkDir &
TargetDatabaseName
If Err = 0 Then
' remove old database
Kill WorkDir & CurrentDatabaseName
Name WorkDir & TargetDatabaseName As WorkDir &
CurrentDatabaseName
Else
MsgBox "Compacting operation failed, couldn't create new
database file " & WorkDir & TargetDatabaseName & 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.Application
appAccess.CloseCurrentDatabase

this gives me an error.

any suggestions
Thanks Alfred

**********************
ja**************@telusTELUS.net
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
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...
5
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",...
1
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...
1
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...
1
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...
1
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...
3
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...
1
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.