If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#11
|
|||
|
|||
Am I missing something?
Thanks very much Allen. That's clear now. Wow, there are so many ways
a save can be triggered. But one final (I hope) point. Does the Form_BeforeUpdate *only* fire when the record is about to be saved? I thought not, so, is there a way to tell 'saving' apart? I have another related issue. In some circumstances after saving a detail record using If Me.Dirty Then Me.Dirty = False 'Save If Not Me.NewRecord Then RunCommand acCmdRecordsGotoNew (the code you showed me), the subform reverts to showing the first detail record. I don't want this behaviour. It should only show data entry in progress or a blank ready for data. Should I post this question as a new thread? -- Len __________________________________________________ ____ remove nothing for valid email address. "Allen Browne" wrote in message ... | Form_BeforeUpate is the *only* way to catch all the possible ways a record | could be saved (e.g. moving to another record, closing the form, applying a | filter/sort, pressing Shift+Enter, using the toolbar/meny/ribbon, closing | Access, ...) | | You should be able to code the event so it only triggers the warnings if | something was changed, e.g.:ww | | Private Sub Form_BeforeUpdate(Cancel As Integer) | Dim strMsg As String | dim bWarn As Boolean | 'Handle the required things first. | If IsNull(Me.Surname) Then | Cancel = True | strMsg =strMsg & "Surname required." & vbCrLf | End If | 'and similarly for other required things. | | If Not Cancel Then | With Me.SomeField | If (.Value = .OldValue) Or (IsNull(.Value) And | IsNull(.OldValue)) Then | 'do nothing: it didn't change | Else | bWarn = True | strMsg = strMsg & "Confirm change to SomeField." & vbCrLf | End If | End With | 'etc for other warnings | | End If | | If Cancel Then | strMsg = strMsg & vbCrLf & "Correct the entry, or press Esc to | undo." | MsgBox strMsg | ElseIf bWarn Then | strMsg = strMsg & vbCrLf & "REALLY?" | If MsgBox(strMsg, vbYesNo + vbDefaultButton2, "Are you sure?") | vbYes Then | Cancel = True | End If | End If | End Sub | | -- | Allen Browne - Microsoft MVP. Perth, Western Australia | Tips for Access users - http://allenbrowne.com/tips.html | Reply to group, rather than allenbrowne at mvps dot org. |
#12
|
|||
|
|||
Am I missing something?
a) Form_BeforeUpdate only fires if a save is about to take place.
b) Something else must be causing the subform to reload. That could be code in its events (e.g. AfterUpdate, AfterInsert, Current), or the control's events (e.g. GotFocus, Enter.) Or, it could be caused by requerying or moving record on the main form. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. ".Len B" wrote in message ... Thanks very much Allen. That's clear now. Wow, there are so many ways a save can be triggered. But one final (I hope) point. Does the Form_BeforeUpdate *only* fire when the record is about to be saved? I thought not, so, is there a way to tell 'saving' apart? I have another related issue. In some circumstances after saving a detail record using If Me.Dirty Then Me.Dirty = False 'Save If Not Me.NewRecord Then RunCommand acCmdRecordsGotoNew (the code you showed me), the subform reverts to showing the first detail record. I don't want this behaviour. It should only show data entry in progress or a blank ready for data. Should I post this question as a new thread? |
#13
|
|||
|
|||
مرحبا
كتب ".Len B" في رسالة ... Thanks very much Allen. That's clear now. Wow, there are so many ways a save can be triggered. But one final (I hope) point. Does the Form_BeforeUpdate *only* fire when the record is about to be saved? I thought not, so, is there a way to tell 'saving' apart? I have another related issue. In some circumstances after saving a detail record using If Me.Dirty Then Me.Dirty = False 'Save If Not Me.NewRecord Then RunCommand acCmdRecordsGotoNew (the code you showed me), the subform reverts to showing the first detail record. I don't want this behaviour. It should only show data entry in progress or a blank ready for data. Should I post this question as a new thread? -- Len __________________________________________________ ____ remove nothing for valid email address. "Allen Browne" wrote in message ... | Form_BeforeUpate is the *only* way to catch all the possible ways a record | could be saved (e.g. moving to another record, closing the form, applying a | filter/sort, pressing Shift+Enter, using the toolbar/meny/ribbon, closing | Access, ...) | | You should be able to code the event so it only triggers the warnings if | something was changed, e.g.:ww | | Private Sub Form_BeforeUpdate(Cancel As Integer) | Dim strMsg As String | dim bWarn As Boolean | 'Handle the required things first. | If IsNull(Me.Surname) Then | Cancel = True | strMsg =strMsg & "Surname required." & vbCrLf | End If | 'and similarly for other required things. | | If Not Cancel Then | With Me.SomeField | If (.Value = .OldValue) Or (IsNull(.Value) And | IsNull(.OldValue)) Then | 'do nothing: it didn't change | Else | bWarn = True | strMsg = strMsg & "Confirm change to SomeField." & vbCrLf | End If | End With | 'etc for other warnings | | End If | | If Cancel Then | strMsg = strMsg & vbCrLf & "Correct the entry, or press Esc to | undo." | MsgBox strMsg | ElseIf bWarn Then | strMsg = strMsg & vbCrLf & "REALLY?" | If MsgBox(strMsg, vbYesNo + vbDefaultButton2, "Are you sure?") | vbYes Then | Cancel = True | End If | End If | End Sub | | -- | Allen Browne - Microsoft MVP. Perth, Western Australia | Tips for Access users - http://allenbrowne.com/tips.html | Reply to group, rather than allenbrowne at mvps dot org. |
|
Thread Tools | |
Display Modes | |
|
|