A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Am I missing something?



 
 
Thread Tools Display Modes
  #11  
Old January 21st, 2010, 11:47 PM posted to microsoft.public.access.forms
.Len B
external usenet poster
 
Posts: 81
Default 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  
Old January 22nd, 2010, 04:30 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default 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  
Old January 28th, 2010, 10:16 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default مرحبا



‏‏كتب ".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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:00 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.