473,397 Members | 2,084 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,397 software developers and data experts.

accessing a database

Hi, could someone tell me how I can check whether a database is open
by name

eg something like db("mydbname")

May 3 '07 #1
8 2162
On 3 May 2007 06:39:41 -0700, colmkav <co******@yahoo.co.ukwrote:

No idea what you are trying to achieve, but if a database is open,
there is an LDB file which you could test for (using the Dir command).
A more elaborate function that would get you the machine name is here
(from a recent post):
http://support.microsoft.com/kb/176670
(That page also has a link to the Jet UserRoster in Access 2000 and
higher)
http://msdn.microsoft.com/archive/de...techniques.asp
(The bottom of this page has the details on using the DLL)

-Tom.

>Hi, could someone tell me how I can check whether a database is open
by name

eg something like db("mydbname")
May 3 '07 #2
actually the problem I have is that I want to compact a db when it
reaches a size but I get error saying the db is open exclusively to
another user (ie through the same process). The db is only open as far
as I know through linked tables. my code never opens it directly.
On 3 May, 16:11, Tom van Stiphout <no.spam.tom7...@cox.netwrote:
On 3 May 2007 06:39:41 -0700, colmkav <colmj...@yahoo.co.ukwrote:

No idea what you are trying to achieve, but if a database is open,
there is an LDB file which you could test for (using the Dir command).
A more elaborate function that would get you the machine name is here
(from a recent post):http://support.microsoft.com/kb/176670
(That page also has a link to the Jet UserRoster in Access 2000 and
higher)http://msdn.microsoft.com/archive/de...ive/en-us/dnar...
(The bottom of this page has the details on using the DLL)

-Tom.
Hi, could someone tell me how I can check whether a database is open
by name
eg something like db("mydbname")- Hide quoted text -

- Show quoted text -

May 3 '07 #3
colmkav wrote:
actually the problem I have is that I want to compact a db when it
reaches a size but I get error saying the db is open exclusively to
another user (ie through the same process). The db is only open as far
as I know through linked tables. my code never opens it directly.
You'll need to close any object in the Front End table that references a linked table in
your Backend. As long as a reference to a data source (table/query) in the backend exists
(perhaps a form or variable in code) you will not be able to gain exclusive use of the BE
..mdb file.

One possible solution is to iterate through all your objects and close them except the
form from which you might need to run the compact. This should break the link to the
back-end and cause removal (deletion) of the .ldb lock file. At this point your app should
open the BE Exclusively and do the compact. If the .ldb lock file exists you are not going
to get exclusive use of the related .mdb file.

Here is part of the solution. This is test code; you should add some better error handling
and you may need to prevent the closing of a form that you want visible during the compact
process.

(That form should be an un-bound one if you want to keep it open. Or, rather, it shouldn't
bind to any data source in the BE .mdb you want to compact.)

But, this code sample just breaks connections between a front-end (FE) and back-end (BE).
If your application is multi-user then this code won't guarantee you can get exclusive use
of the BE .mdb.

There are many approaches you can take with a multi-user application. You could kick all
users out of the database (DataStrat's KickEmOff - http://www.datastrat.com/Download2.html
- Arvin Meyer) and then run this code and finally your compact routine.

You might also use a more opportunistic approach where you attempt to gain exclusive
access of the BE .mdb and if you can't you fail silently knowing that you'll eventually
get exclusive access. If you application is in use (or at least logged into with a
reference to a linked table in the BE) 24 x 7 then this approach isn't going to work.

At any rate, hope this helps a bit.

Private Sub closeAllObjects()
On Error GoTo errHandler

' close any forms except the one that called this class
Dim intx As Integer
Dim intCount As Integer
Dim ctl As Control, subctl As Control
Dim frm As Access.Form, rpt As Access.Report

' close all open forms
intCount = Forms.Count - 1

For intx = intCount To 0 Step -1
If Forms(intx).Name <m_sCallingForm Then
' close any subforms
For Each ctl In Forms(intx).Controls
If ctl.ControlType = acSubform Then
Set frm = Forms(intx).Controls(ctl.Name).Form
' search the subform for subforms
For Each subctl In frm.Controls
If subctl.ControlType = acSubform Then
frm.Controls(subctl.Name).SourceObject = ""
End If
Next subctl

Forms(intx).Controls(ctl.Name).SourceObject = ""
End If
Next ctl
Forms(intx).Visible = False
DoCmd.Close acForm, Forms(intx).Name
End If
Next

intCount = Reports.Count - 1

For intx = intCount To 0 Step -1
' close any subreports
For Each ctl In Reports(intx).Controls
If ctl.ControlType = acSubform Then
Set rpt = Reports(intx).Controls(ctl.Name).Form
' search the subform for subforms
For Each subctl In rpt.Controls
If subctl.ControlType = acSubform Then
rpt.Controls(subctl.Name).SourceObject = ""
End If
Next subctl

Reports(intx).Controls(ctl.Name).SourceObject = ""
End If
Next ctl

Reports(intx).Visible = False
DoCmd.Close acReport, Reports(intx).Name
Next

exitHandler:
Exit Sub

errHandler:
Debug.Print "Linker: closeAllObjects: " & Err.Description & " (" & Err.Number & ")"
Resume exitHandler

End Sub

--
---------------
John Mishefske, Microsoft Access MVP
May 4 '07 #4

"John Mishefske" <jm**********@SPAMyahoo.comschreef in bericht news:46**********************@roadrunner.com...
Private Sub closeAllObjects()
On Error GoTo errHandler

' close any forms except the one that called this class
Dim intx As Integer
Dim intCount As Integer
Dim ctl As Control, subctl As Control
Dim frm As Access.Form, rpt As Access.Report

' close all open forms
intCount = Forms.Count - 1

For intx = intCount To 0 Step -1
If Forms(intx).Name <m_sCallingForm Then
' close any subforms
For Each ctl In Forms(intx).Controls
If ctl.ControlType = acSubform Then
Set frm = Forms(intx).Controls(ctl.Name).Form
' search the subform for subforms
For Each subctl In frm.Controls
If subctl.ControlType = acSubform Then
frm.Controls(subctl.Name).SourceObject = ""
End If
Next subctl

Forms(intx).Controls(ctl.Name).SourceObject = ""
End If
Next ctl
Forms(intx).Visible = False
DoCmd.Close acForm, Forms(intx).Name
End If
Next

intCount = Reports.Count - 1

For intx = intCount To 0 Step -1
' close any subreports
For Each ctl In Reports(intx).Controls
If ctl.ControlType = acSubform Then
Set rpt = Reports(intx).Controls(ctl.Name).Form
' search the subform for subforms
For Each subctl In rpt.Controls
If subctl.ControlType = acSubform Then
rpt.Controls(subctl.Name).SourceObject = ""
End If
Next subctl

Reports(intx).Controls(ctl.Name).SourceObject = ""
End If
Next ctl

Reports(intx).Visible = False
DoCmd.Close acReport, Reports(intx).Name
Next

exitHandler:
Exit Sub

errHandler:
Debug.Print "Linker: closeAllObjects: " & Err.Description & " (" & Err.Number & ")"
Resume exitHandler

End Sub

--
---------------
John Mishefske, Microsoft Access MVP
Hi John,

Wouldn't it be sufficient to just close the open forms and reports?
I mean: Why are you testing for subforms and subreports?
They are not part of the collection ... or??

I am using code like this for years to close all forms:
Do Until Forms.Count = 0
FormName = Forms(intAantalForms - 1).Name
DoCmd Close acForm, FormName
Loop

Same thing for reports I guess.

Arno R
May 4 '07 #5
Arno R wrote:
Wouldn't it be sufficient to just close the open forms and reports?
I mean: Why are you testing for subforms and subreports?
They are not part of the collection ... or??

I am using code like this for years to close all forms:
Do Until Forms.Count = 0
FormName = Forms(intAantalForms - 1).Name
DoCmd Close acForm, FormName
Loop

Same thing for reports I guess.
Hi Arno. I pulled this from an older project. I recall that I added the subform/subreport
code after my initial implementation in response to some bug/problem but I can't recall
what it was and, unfortunately, I didn't document the reason.

I agree with you; closing the form would also close the form in the subform control but I
distinctly remember going back and adding the code for the subform/subreports after some
problem made me go back and review the code.

If I get some time I'll try to determine the reason. At first I thought it might be that
the code is from VB6 where I have implemented a class to support subforms but this line

Dim frm As Access.Form, rpt As Access.Report

pretty much confirms it was from Access.

--
---------------
John Mishefske, Microsoft Access MVP
May 5 '07 #6

"John Mishefske" <jm**********@SPAMyahoo.comschreef in bericht news:46***********************@roadrunner.com...
Arno R wrote:
>Wouldn't it be sufficient to just close the open forms and reports?
I mean: Why are you testing for subforms and subreports?
They are not part of the collection ... or??

I am using code like this for years to close all forms:
Do Until Forms.Count = 0
FormName = Forms(intAantalForms - 1).Name
DoCmd Close acForm, FormName
Loop

Same thing for reports I guess.
Hi Arno. I pulled this from an older project. I recall that I added the subform/subreport
code after my initial implementation in response to some bug/problem but I can't recall
what it was and, unfortunately, I didn't document the reason.

I agree with you; closing the form would also close the form in the subform control but I
distinctly remember going back and adding the code for the subform/subreports after some
problem made me go back and review the code.

If I get some time I'll try to determine the reason. At first I thought it might be that
the code is from VB6 where I have implemented a class to support subforms but this line

Dim frm As Access.Form, rpt As Access.Report

pretty much confirms it was from Access.

--
---------------
John Mishefske, Microsoft Access MVP

Hi John,

I did some testing with open forms that have subform controls (several levels deep)
Sub test()
Dim i As Integer, msg As String
For i = 0 To Forms.Count - 1
msg = msg & vbNewLine & Forms(i).Name
Next i
MsgBox "Open forms:" & msg
End Sub

The subforms are not mentioned.
Only when I open a subform seperately *as a form*, then it is part of the collection of open forms.

I would be very interested if you could determine your reason for the subform/report test.

Arno R

May 5 '07 #7
Arno,

Just for the record, there is no such object as a "Subform" or a "Subreport"
in Access; there is a "Subform Control" and a "Subreport Control" into which
you may embed Forms. The embedded Form, when it is displayed in the Subform
Control does not exist as an instance of the Form (e.g., is not "Open"), and
thus is not in the Forms Collection (which contains only Open Forms). The
same applies to Reports and Subreport Controls.

It exists as the Form property of the Subform Control, and that is the
(only) appropriate way to refer to it.

I'm not aware of all the considerations that entered into the design
decisions in this area, but that's the way it works.

Larry Linson
Microsoft Access MVP
May 6 '07 #8
Arno R wrote:
I did some testing with open forms that have subform controls (several levels deep)
Sub test()
Dim i As Integer, msg As String
For i = 0 To Forms.Count - 1
msg = msg & vbNewLine & Forms(i).Name
Next i
MsgBox "Open forms:" & msg
End Sub

The subforms are not mentioned.
Only when I open a subform seperately *as a form*, then it is part of the collection of open forms.

I would be very interested if you could determine your reason for the subform/report test.
Yes, Larry pointed this out as well. Forms opened in a subform control are not considered
an open form in the Forms collection.

I can't recall the reason; the only thing I can surmise is that perhaps the form in the
subform control is bound and the parent isn't. But I would still assume closing the parent
form would close the form in the subform control and thus close the binding to the data
source. If I had more time right now I'd test that. If I run across the reasoning I'll
post back.

Also, I do seem to recall that there were tertiary forms and that was part of the issue
and why that code went to that level.

But obviously, since I can't justify my reasoning, we'll have to call it programmer error
or at least oversight for not properly documenting the reason.

--
---------------
John Mishefske, Microsoft Access MVP
May 6 '07 #9

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

Similar topics

3
by: Scott Castillo | last post by:
Is it possible to access an SQL Server database from a Javascript client? I know you can transfer variables from middleware to Javascript client, but was wondering if you can directly access...
2
by: Douglas Harber | last post by:
If I have DB2 8.1 (FP5, I believe, but not relevant to my question...I hope) installed on my desktop, do I have what I need to connect to a remote DB2 server (also running 8.1 FP5) from my desktop...
3
by: prodirect | last post by:
Hi all, I hope someone can help me. I've recently created a database and wanted to put it up on an ftp sight so that multiple people could access the same tables at the same time from different...
2
by: DanB | last post by:
I am using VB DotNet Std Edition and am writing a web application that needs to read and write to an password protected database. The mdb files reside in a folder (fpdb) under the localhost...
3
by: mark.jerrom | last post by:
I'm fairly new to this Web Service game so please feel free to suggest something different if it looks like i'm completely off track! I'm trying to write an application that runs on a Pocket PC...
3
by: Pakna | last post by:
Hello, I have what may be a beginner's question regarding DB2. How does one access a remote table on a remote database via SQL? What is the command string, is there an equivalent of Oracle...
5
by: samadams_2006 | last post by:
I'm having a problem in accessing a Microsoft Access Database in a VB.NET Web Application. It's so straight forward, I thought I'd walk you through all the details here: 1) I have a .NET Web...
4
by: scout3014 | last post by:
Hi I am using WAMP5 to create web applications. I have a problem as far as accessing the database is concerned. This following code is used to access database: $con =...
4
by: Noy B | last post by:
Hi, I have developed a small application that is using a MSAccess DB. the problem is that it was developed on a machine where the application and the DB are both located. now it needs to be...
2
by: brendan_gallagher_2001 | last post by:
HI I am developog an ASP.net site (using vb.net 1.1) which will be accessed by a number of different office locations, where certain users will be assigned a authoriser profile, and others will...
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:
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...
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
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,...
0
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...

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.