내 수업 데이터베이스에 대한 마지막 질문이 하나 있습니다. 사용자가 데이터를 볼 수있는 특정 양식의 경우 양식을 닫고 변경하지 않은 경우 메시지를 표시하지 못하게 할 수 있습니다. 그러나 양식의 일부 데이터를 변경하고 레코드를 편집한다고 선택하면 변경 사항을 저장할지 묻는 팝업 상자가 표시되기를 원합니다. 그들이 예를 선택하면 이전 레코드를 덮어 쓰고 변경 사항을 레코드에 저장하지만, 아니오를 선택하면 레코드가 전혀 변경되지 않고 양식이 닫힙니다.사용자가 양식을 저장하라는 메시지가 표시됩니다.
어떻게하면됩니까? Access 2016을 사용하고 있으며 지금까지 시도한 결과 오류가 발생합니다. 다음은 VBA의 BeforeUpdate 이벤트 양식에서 시도한 두 가지 방법입니다.
방법 1 :
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim iResponse As Integer
' Specify the message to display.
strMsg = "Do you wish to save the changes?" & Chr(10)
strMsg = strMsg & "Click Yes to Save or No to Discard changes."
' Display the message box.
iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?")
' Check the user's response.
If iResponse = vbNo Then
' Undo the change.
DoCmd.RunCommand acCmdUndo
' Cancel the update.
Cancel = True
End If
End Sub
Error - "The expression Before Update you entered as the event property setting produced the following error: A problem occured while Microsoft Access was communicated with the OLE server or ActiveX Control."
방법 2 :
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Provide the user with the option to save/undo
'changes made to the record in the form
If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub
오류 - 위와 동일합니다.
도움을 주시면 대단히 감사하겠습니다.
감사합니다.
감사 하위 Exit_BeforeUpdate 끝을 다시 시작 . 저는 Access에서 더 공부해야 할 것입니다. – Adam