25. august 2003 - 11:47Der er
11 kommentarer og 3 løsninger
Genstart database
Findes der ikke en simpel eller rimelig simpel måde til at genstarte en Access program. Jeg kan sikker godt lave noget med at jeg kalder en anden database, som sørger for at lukke den første ned, starte den igen og tilsidst lukker sig selv, men hvis der nu findes en nemmere måde at gøre det på, ville det være at foretrække?
' 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.
'***************** 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
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
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?
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.