2013-02-20 31 views
0

我一直在上網的結婚尋找一個答案,我認爲這是一個非常簡單的問題,對於像我這樣的新手。但還沒有發現任何所以我在這裏!爲了簡單起見,我將附上兩段代碼,這些代碼讓我感到頭疼。我打算做的是通過單擊按鈕從只讀模式切換到允許寫入狀態。爲了做到這一點,我想常規檢查記錄在案的變化,如果有任何要求用戶決定是否保存更改或放棄它們。雖然測試這個特定的按鈕,我發現了一些相當「有趣「..當沒有改變時,它似乎運作良好。從只讀狀態切換到寫入允許狀態。然而,當寫允許並進行了更改,如果已經選擇了「保存選項」 /點擊話雖然所有其他的子程序和變化中實現它不鎖定的內容。只讀和撤消性質的MS Access(VBA)

我的另一個問題,與之密切相關的是,我不能找到一種方法來設置一個「節約點」撤消選項。我想找到一種方法來「保存記錄」,所以當撤銷按鈕被按下犯規撤消所有更改的記錄遭受因爲數據庫已經首先開通(爲目前發生的事情),但由於按鈕已被按下。我試過的DoCmd保存功能,但並不表現爲我所期待的(注:最後的「其他」一直是我的最後一次嘗試解決這個問題,但同樣,它不是按預期工作)

所有你的未來非常感謝協作,

亞歷

Private Sub Command28_Click() 
    If Form_AODNewRecord.AllowAdditions = True Then 
     Call isModified_Save 

     Form_AODNewRecord.AllowAdditions = False 
     Form_AODNewRecord.AllowEdits = False 
     Form_AODNewRecord.AllowDeletions = False 
     MsgBox "Read Only. Addition, Edits and Deletions are now locked" 
     Command28.Caption = "LOCKED" 
    Else 
     Form_AODNewRecord.AllowAdditions = True 
     Form_AODNewRecord.AllowEdits = True 
     Form_AODNewRecord.AllowDeletions = True 
     MsgBox "New records, edits and deletions are now allowed" 
     Command28.Caption = "Lock mode OFF" 
    End If 

    MsgBox Form_AODNewRecord.AllowAdditions 
End Sub 

Sub isModified_Save() 
    If Form_AODNewRecord.Dirty Then 
     Dim strMsg As String, strTitle As String 
     strMsg = "You have edited this record. Do you want to save the changes?" 
     strTitle = "Save Record?" 
     If MsgBox(strMsg, vbQuestion + vbYesNo, strTitle) = vbNo Then 
      Me.Undo 
     Else 
      DoCmd.OpenTable "AOD Type", acViewPreview, acReadOnly 
      DoCmd.Save acTable, "AOD Type" 
      DoCmd.Close acTable, "AOD Type", acSaveYes 

     End If 
    End If 

End Sub 

回答

0

我想你想下面的代碼。您無法打開表單綁定並影響表單的表格,當您打開表格時,您有兩個不同的實例並且它們不會互相影響。

在Office應用程序中運行宏的一個奇怪的副作用是它清除了撤消列表,因此我創建了一個只顯示消息「撤消清除」的小宏,這正是它的作用!

順便說一句,重命名有意義的名稱,如cmdLock,而不是Command28你的控制,你以後會感謝自己。

Private Sub Command28_Click() 
    If Me.AllowAdditions = True Then 
     Call isModified_Save 

     Me.AllowAdditions = False 
     Me.AllowEdits = False 
     Me.AllowDeletions = False 
     MsgBox "Read Only. Addition, Edits and Deletions are now locked" 
     Command28.Caption = "LOCKED" 
    Else 
     Me.AllowAdditions = True 
     Me.AllowEdits = True 
     Me.AllowDeletions = True 
     MsgBox "New records, edits and deletions are now allowed" 
     Command28.Caption = "Lock mode OFF" 
    End If 

    ''MsgBox Me.AllowAdditions 
End Sub 

Sub isModified_Save() 
    If Me.Dirty Then 
     Dim strMsg As String, strTitle As String 
     strMsg = "You have edited this record. Do you want to save the changes?" 
     strTitle = "Save Record?" 
     If MsgBox(strMsg, vbQuestion + vbYesNo, strTitle) = vbNo Then 
      Me.Undo 
     Else 
      ''Save record 
      Me.Dirty = False 
      ''Clear undo list 
      DoCmd.RunMacro "ClearUndo" 
     End If 
    End If 

End Sub 
+0

非常感謝,我只是意識到你回答我的問題。將看它提供適當的反饋;) – user1872905 2013-02-27 16:04:08