Du kan lave et batchjob i DOS, som kalder access med din database. Du kan så kalde den og efterfølgende afslutte Access.
Just out of interest, what do you want to do thi sfor?
Du kan godt snyde lidt ved at lave en "komprimer database-funktion", som lukker, og genåbner db'en.. jeg kan sende en testdb?!
ferdinand>> kan du ikke bare lige vise koden her
jeg har et par stykker du kan se hvis du vil, de kan lidt mere end du beder om...
Prøv nedenstående:
Private Sub cmdCheckup_Click()
' Do the actual work
On Error GoTo cmdCheckup_Err
Dim db As Database
Dim ws As Workspace
Dim strDB As String
Dim strLDB As String
Dim strNewDB As String
strDB = CStr(Me![txtFile])
' First, check to make sure we can get to the database exclusively
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(strDB, True)
'Next, whack the locking file
strLDB = Left$(strDB, Len(strDB) - 3) & "LDB"
Kill strLDB
' Repair the database
db.Close
DBEngine.RepairDatabase strDB
' Compact the database
strNewDB = Left$(strDB, Len(strDB) - 1) & "N"
DBEngine.CompactDatabase strDB, strNewDB
' Kill the old database
Kill strDB
' And rename the new one
Name strNewDB As strDB
' Tell the user all is well
MsgBox "Checkup completed successfully"
' And close
DoCmd.Close A_FORM, Me.Name
cmdCheckup_Exit:
Exit Sub
cmdCheckup_Err:
Select Case Err
Case 3356 ' Couldn't open exclusively
MsgBox "The file is open on another machine. Cannot complete checkup. Please close and try again."
Case Else
MsgBox "Error " & Err & ": " & Error$, 16, "Call Programmer"
End Select
Resume cmdCheckup_Exit
End Sub
terry>> det jeg ønsker er, jeg har en rutine som spærrer for shift-start, for at undgå at der kan ændres direkte i tabellerne. Men der skal være mulighed for at dem som har administrator rettigheder til databasen, at de må gå direkte ind. Jeg styrer selv alt det med logon og rettigheder.
Jeg har så oprettet et menupunkt 'Unlock database', som kun kan køres af dem som har administrator rettighed, og det er her problemet kommer, for nu skal programmet jo genstartes for at der er adgang.
Men hvis der findes en kommando der kan kalde database-vinduet frem, vil det også løse problemet, det vil faktisk være en bedre løsning.
place this in a module
Option Compare Database
Option Explicit
'***************** Code Start *****************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function FindWindowEx _
Lib "user32" Alias "FindWindowExA" _
(ByVal hwndParent As Long, _
ByVal hwndChildAfter As Long, _
ByVal lpszClass As String, _
ByVal lpszWindow As String) _
As Long
Private Declare Function GetWindowLong _
Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) _
As Long
Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000
Public Function fIsDBCVisible() As Boolean
'
' Returns true if the Database container
' window is currently visible
'
Dim lngStyle As Long
Dim hWnd As Long
Const WC_MDICLIENT = "MDIClient"
Const WC_DBC = "Odb"
' Find the MDIClient window first
hWnd = FindWindowEx(hWndAccessApp, 0, _
WC_MDICLIENT, vbNullString)
' Find the db container window
hWnd = FindWindowEx(hWnd, 0, WC_DBC, vbNullString)
If (hWnd) Then
' retrieve the window style
lngStyle = GetWindowLong(hWnd, GWL_STYLE)
fIsDBCVisible = ((lngStyle And WS_VISIBLE) = WS_VISIBLE)
End If
End Function
'***************** Code Start *****************
Then place this on a form with a button
Function ToggleDbWindowState()
'To show the database window, run
If Not fIsDBCVisible Then
DoCmd.SelectObject acTable, , True
Else
'To Hide the database window, run
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
End If
End Function
Private Sub Command2_Click()
ToggleDbWindowState
End Sub
and some extras :o)
You need two mor ebuttons
Private Sub Command0_Click()
WindowReSize "Max"
End Sub
Private Sub Command1_Click()
WindowReSize "Min"
End Sub
you can also hide the tables, right click on the table, choose properties and then hidden
Jeg fandt flg.
DoCmd.SelectObject acForm, , True
Den gør det jeg spurgte om ang. vis databasevindue
terry>> Så er det ikke lidt overkill at have så meget kode, som i dit eksempel eller er der noget jeg overser.
Jeg kan godt se at med din kode er det mulig at skifte tilstand fra skjult og ikke skjult ved hjælp af en knap.
The code was given as is to give you some ideas. If DoCmd.SelectObject acForm, , True
does what you want then you find what you wanted from this code IKKE?
terry>> Nej jeg fandt koden et andet sted, så det var ikk pga. din kode.
Men i kan dele pointene som tak for at i svarede.