Logo

MS Access FAQ - Database

Logo

Table of Contents (4 Questions)

Bullet Database doesn't shrink after deleting something
Bullet Prevent Users Opening a Database Exclusively
Bullet Change Main window Title
Bullet Opening another Database


Q I just deleted a lot of records and other objects from my database and it hasn't got any smaller, why?
Back to Top
A Access does not recover free space immediately, under some circumstances it will re-use the deleted space for new objects and records so the size of the database file will not grow for a long time.

However, if you want to regain the space then simply compact the database.

Updated: 08/11/1996 - Trevor Best


Back to Top
Q How can I prevent users from opening a shared database exclusively
Back to Top
A A Simple procedure or function called from the Autoexec macro should do the trick:

Sub CheckSharedOpen ()
    On Error GoTo CheckSharedOpen_Err
    Dim db As Database, strDb As String, hFile As Integer
    Set db = dbengine(0)(0)
    ' Get file name of current database
    strDb = db.name
    hFile = FreeFile
    ' Attempt to open database file, if opened exclusively then this will fail with an error
    Open strDb For Input Access Read Shared As #hFile
    Close #hFile
CheckSharedOpen_Exit:
    Exit Sub
CheckSharedOpen_Err:
    Select Case Err
        Case 70 ' Persmission Denied (Share violation)
            MsgBox "You are not allowed to open this database exclusively", 16
            Application.Quit A_EXIT
        Case Else
            MsgBox Error, 16, "Error #" & Err & " in CheckSharedOpen()"
    End Select
    Resume CheckSharedOpen_Exit
End Sub

Updated: 18/01/1997 - Trevor Best


Back to Top
Q How can I change the Title of the MS-Access title bar?
Back to Top
A Access 2.0
The simple way, In the .ini file:

[run-time options]
TitleBar=My Text
StartupScreen=mypic.bmp
Icon=MyIcon.ico

Or dynamically in code:

Declare Sub WinApi16_SetWindowText Lib "User" Alias "SetWindowText" (ByVal hWnd As Integer, ByVal lpString As String)
Declare Function WinApi16_GetParent Lib "User" Alias "GetParent" (ByVal hWnd As Integer) As Integer


Sub SetTitle ( pstrText As String)
Dim hWndAccess As Integer
' open up a form that's small and light
DoCmd OpenForm "frmSmall"
' Make it invisible
Forms!frmSmall.Visible = False
DoEvents
' get it's window handle
hWndAccess = forms!frmSmall.hWnd
' trace back to main access window handle
Do Until WinApi16_GetParent(hWndAccess) = 0
hWndAccess = WinApi16_GetParent(hWndAccess)
Loop
DoCmd Close A_FORM, "zsfrmBackground"

WinApi16_SetWindowText hWndAccess, pstrText
End Sub

Access 97
Database properties?

Updated: 22/12/1997 - Trevor Best


Back to Top
Q How can I open another database from code
Back to Top
A My startup application does this, it just uses SendKeys to automate an otherwise manual procedure as Access wasn't designed to do this, e.g. if the other database name is in a string variable (strDb) then the following code will open it.

SendKeys "{F11}%FO" & strDb & "{enter}"


You may want to check when running version 2.0 in Win95 or NT that the path name doesn't contain tildes ("~") as these tend to break it.

Updated: 16/11/1997 - Trevor Best


Back to Top