UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Macro On Leaving Recordset, Access 2016    
 
   
Mister-B
post May 24 2019, 04:58 AM
Post#1



Posts: 2
Joined: 26-August 18



Hi,

to make sure that all fields on my form are correctly filled, I am trying to get a macro to fire when I leave the current record. Here's the Code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not NewRecord Then
If IsNull(Me.ZurGA) And IsNull(Me.cboWV) Then
If MsgBox("Blah, blah?", vbYesNo) = vbYes Then GoTo Jump
Me.cboWV.SetFocus
Cancel = True
End If
End If

Jump:
End Sub

Unfortunately the macro is firing when I enter the record and not when it leaves. What am I doing wrong?
Go to the top of the page
 
Phil_cattivocara...
post May 24 2019, 05:17 AM
Post#2



Posts: 283
Joined: 2-April 18



It is not neccessary to verify it you are in a new record, I think.
Comment first If (and last End If, of course)

--------------------
Please forgive in advance my horrible English.
Go to the top of the page
 
moke123
post May 24 2019, 05:21 AM
Post#3



Posts: 1,359
Joined: 26-December 12
From: Berkshire Mtns.


CODE
If Not NewRecord Then

This should probably be Me.NewRecord.
This is only going to fire with existing records that have been dirtied. What about new records?

CODE
If IsNull(Me.ZurGA) And IsNull(Me.cboWV) Then

This is only going to fire if both fields are null. What if only one of them is null?
Are you sure you dont want Or instead of And?


Go to the top of the page
 
Mister-B
post May 24 2019, 07:29 AM
Post#4



Posts: 2
Joined: 26-August 18



Yes, I only want it to fire when both fields are empty. The code works fine. It's just that it fires when I enter the report and not when I leave it.
Go to the top of the page
 
gemmathehusky
post May 24 2019, 07:34 AM
Post#5


UtterAccess VIP
Posts: 4,693
Joined: 5-June 07
From: UK


it can't fire when you enter a new record.

the form beforeupdate event fires immediately before you try to save a record. If the sub is not cancelled, then the record saves. It's firing when you save the previous record, not when you start a new record. Both events appear to happen together, so that might be the issue.




--------------------
Dave (Male)

(Gemma was my dog)
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    25th June 2019 - 07:11 AM