Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 04-12-2011, 03:05 PM   #1
pdanes
Newly Registered User
 
Join Date: Apr 2011
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
pdanes is on a distinguished road
Question Change display in OnCurrent event not working

I have a form with a "Make Copy" button. The database has many records which are very similar in content. This button allows the user to select a record similar to what he wants to enter, make a copy and edit the copy, rather than having to type everything every time. This all works fine.

In order to help cut down confusion, when the duplicate record is created and displayed, I make visible the label border for every field that is filled by code, then when the user exits that field on the form, I hide the label border again. This provides a visual record of which fields have been visited (and possibly changed). This works great as well.

When the user finishes modifying the record, I clear any remaining visible borders in the form's AfterUpdate event, so that all borders are invisible again when the user goes to another record. Once again, all is good.

My problem is when the user leaves the freshly created record -without- having made any changes. There are no changes made, so the AfterUpdate event doesn't fire, and the cautionary borders remain visible. I tried clearing them in the OnCurrent event when the next record comes in, but the code simply doesn't work there. No errors, but nothing happens, the borders remain. Even when I put in a breakpoint and step the code, the borders do not get cleared. Even when I issue the appropriate command in the immediate window, nothing happens, if I do it while within the bounds of the paused OnCurrent event code. The exact same code, running or immediate works fine when called from anywhere else.

I'm using A2007 under Vista. No net search has brought up any posts about this, or at least I haven't found any, but keywords addressing this are common and results number in the hundreds of thousands.

Is there something special about the OnCurrent event that prevents screen updates? Is there another way to clear these borders when leaving an unmodified record? Might there be a better way to do the whole thing?

pdanes is offline   Reply With Quote
Old 04-12-2011, 04:10 PM   #2
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,800
Thanks: 55
Thanked 1,028 Times in 994 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
Re: Change display in OnCurrent event not working

how does the user leave the record without making changes?

there should be a current event for the next record

however - is your form unbound? If so, that might mean you dont get a current event
__________________
Dave (Male!)
Gemma was my dog

if a poster helps you, please click the scales at the bottom left of this posting, or use the thanks button alongside.
gemma-the-husky is offline   Reply With Quote
Old 04-12-2011, 04:28 PM   #3
pdanes
Newly Registered User
 
Join Date: Apr 2011
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
pdanes is on a distinguished road
Re: Change display in OnCurrent event not working

Quote:
Originally Posted by gemma-the-husky View Post
how does the user leave the record without making changes?
My code creates a new record and populates the fields on the form, so the user is left sitting on a newly created record. If he then clicks one of the navigation buttons, or presses PageUp/PageDn, he moves to another record, without having made any changes to the newly created record, so the AfterUpdate event does not fire.

Quote:
there should be a current event for the next record
There is and it fires correctly. If you look at my post again, you'll see that I write about using it and stopping code execution in it.

Quote:
however - is your form unbound? If so, that might mean you dont get a current event
No, the form is bound, and again, the event DOES fire, as I write in my original post. The problem is that the code doesn't do anything, if it's called from the OnCurrent event. Yes, it's executing, I have put in breakpoints to verify that it is. Other stuff that I do in the OnCurrent event works fine, and this same code called from other places works fine, just the changing of the label border properties -FROM THE ONCURRENT EVENT- doesn't do anything.

pdanes is offline   Reply With Quote
Old 04-12-2011, 04:51 PM   #4
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,312
Thanks: 11
Thanked 719 Times in 669 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Change display in OnCurrent event not working

Don't understand why the Form_Current event isn't working here, but if it were working and this meets your needs, you should be able to reset the formatting in the Form_BeforeUpdate event. This event fires if a record is saved, whether it is physically populated thru the keyboard or thru code.

Also, if no changes are made to the record after its creation, aren't you, ipso facto, creating a totally duplicate record?

Linq ;0)>
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 04-13-2011, 01:05 AM   #5
pdanes
Newly Registered User
 
Join Date: Apr 2011
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
pdanes is on a distinguished road
Re: Change display in OnCurrent event not working

Quote:
Originally Posted by missinglinq View Post
Don't understand why the Form_Current event isn't working here, but if it were working and this meets your needs, you should be able to reset the formatting in the Form_BeforeUpdate event. This event fires if a record is saved, whether it is physically populated thru the keyboard or thru code.
I don't understand why either, that's why I'm here, hoping that someone else does. The BeforeUpdate event has the same shortcomings as the AfterUpdate event - it doesn't fire if the user navigates away from the record without making any changes.
Quote:
Also, if no changes are made to the record after its creation, aren't you, ipso facto, creating a totally duplicate record?

Linq ;0)>
Yes, that can happen. There is nothing in this database that prevents the creation of identical records (except for the autonumber primary key). It's not common, but it is a perfectly legitimate occurrence.
pdanes is offline   Reply With Quote
Old 04-13-2011, 01:26 AM   #6
spikepl
Eledittingent Beliped
 
spikepl's Avatar
 
Join Date: Nov 2010
Location: San Serriffe
Posts: 6,144
Thanks: 77
Thanked 980 Times in 958 Posts
spikepl is a jewel in the rough spikepl is a jewel in the rough spikepl is a jewel in the rough
Re: Change display in OnCurrent event not working

"No, the form is bound, and again, the event DOES fire, as I write in my original post. The problem is that the code doesn't do anything," How do you know? Have you checked what the acutal value of the property that you set is at the beginning and at the end of the OnCurrent- code? One could theorize that the code runs fine, but the property is unexpectedly set elsewhere afterwords.

In the debugger, you could put a Watch on the property, to see if it gets changed when expected/desired
spikepl is offline   Reply With Quote
Old 04-13-2011, 01:28 AM   #7
spikepl
Eledittingent Beliped
 
spikepl's Avatar
 
Join Date: Nov 2010
Location: San Serriffe
Posts: 6,144
Thanks: 77
Thanked 980 Times in 958 Posts
spikepl is a jewel in the rough spikepl is a jewel in the rough spikepl is a jewel in the rough
Re: Change display in OnCurrent event not working

Besides - have you tried .Repaint?

spikepl is offline   Reply With Quote
Old 04-13-2011, 02:12 AM   #8
pdanes
Newly Registered User
 
Join Date: Apr 2011
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
pdanes is on a distinguished road
Re: Change display in OnCurrent event not working

Quote:
Originally Posted by spikepl View Post
"No, the form is bound, and again, the event DOES fire, as I write in my original post. The problem is that the code doesn't do anything," How do you know? Have you checked what the acutal value of the property that you set is at the beginning and at the end of the OnCurrent- code?
Did you read my original post? Yes, I -KNOW- it doesn't do anything, because I put a breakpoint into the OnCurrent event code, and stepped the code manually. I have executed the code step by step, and examined both the screen and the actual values in the immediate window right after executing the commands to change the property. It doesn't change. Even when I type the command directly into the immediate window while the OnCurrent event code is paused, the value doesn't change. All this was in my original post.
Quote:
One could theorize that the code runs fine, but the property is unexpectedly set elsewhere afterwords.
One could, but that's not what's happening. The property value simply doesn't change.
Quote:
In the debugger, you could put a Watch on the property, to see if it gets changed when expected/desired
I have - it doesn't.
Quote:
Besides - have you tried .Repaint?
Yes, but since the property value doesn't change, Repaint doesn't help. It repaints the screen, but with the unchanged values.
pdanes is offline   Reply With Quote
Old 04-13-2011, 05:11 AM   #9
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,312
Thanks: 11
Thanked 719 Times in 669 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Change display in OnCurrent event not working

Quote:
Originally Posted by pdanes View Post
The BeforeUpdate event has the same shortcomings as the AfterUpdate event - it doesn't fire if the user navigates away from the record without making any changes.
Not true! The form's BeforeUpdate event, Form_BeforeUpdate, fires any time a record is saved, even if the only data in the record has been populated thru code!

Linq ;0)>
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 04-13-2011, 05:32 AM   #10
pdanes
Newly Registered User
 
Join Date: Apr 2011
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
pdanes is on a distinguished road
Re: Change display in OnCurrent event not working

Quote:
Originally Posted by missinglinq View Post
Not true! The form's BeforeUpdate event, Form_BeforeUpdate, fires any time a record is saved, even if the only data in the record has been populated thru code!

Linq ;0)>
Well, I tried it this morning, put a breakpoint into the event handler. Pressed the 'Make Copy' button, let the code run to make the new record, then moved to another record. Neither the BeforeUpdate nor the AfterUpdate event fired. When I do the same thing, but make any sort of manual change to any of the fields before moving away, both events fire (both stop at the defined breakpoints and display the VBE).
pdanes is offline   Reply With Quote
Old 04-13-2011, 08:28 AM   #11
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,312
Thanks: 11
Thanked 719 Times in 669 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Change display in OnCurrent event not working

I just
  • Put a messagebox in the Form_BeforeUpdate event
  • Made a new record
  • Populated fields on the new record with code
  • Did nothing else to the record
  • Navigated away to another record and the message box appeared, as expected, showing that the event had fired.
Maybe we need to look at the code behind your 'make a copy' button.
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 04-13-2011, 03:20 PM   #12
pdanes
Newly Registered User
 
Join Date: Apr 2011
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
pdanes is on a distinguished road
Re: Change display in OnCurrent event not working

Quote:
Originally Posted by missinglinq View Post
I just
  • Put a messagebox in the Form_BeforeUpdate event
  • Made a new record
  • Populated fields on the new record with code
  • Did nothing else to the record
  • Navigated away to another record and the message box appeared, as expected, showing that the event had fired.
Maybe we need to look at the code behind your 'make a copy' button.
Okay, here's the 'MakeCopy' code, called from a ribbon button, hence the explicit reference to the form. Sets a clone pointer to the current record in the form, adds a new record to the form's recordset, then copies everything from the clone to the current new record. The last line calls the routine to make the label borders visible, which routine is reproduced further down. FWIW, the next-to-last line is my current work-around, to force the record to be dirty, that way any movement away triggers the update events, regardless of whether the user made any changes or not.

Code:
Public Sub Kopirovat(control As IRibbonControl)
Dim rst As DAO.Recordset
With Form_Data
    Set rst = .RecordsetClone
    With .Recordset
        .AddNew
        .Fields("DruhAutoID") = IIf(IsNull(rst.Fields("DruhAutoID")), Null, rst.Fields("DruhAutoID"))
        .Fields("RokStary") = IIf(IsNull(rst.Fields("RokStary")), Null, rst.Fields("RokStary"))
        .Fields("MesicStary") = IIf(IsNull(rst.Fields("MesicStary")), Null, rst.Fields("MesicStary"))
        .Fields("DenStary") = IIf(IsNull(rst.Fields("DenStary")), Null, rst.Fields("DenStary"))
        .Fields("RokNovy") = IIf(IsNull(rst.Fields("RokNovy")), Null, rst.Fields("RokNovy"))
        .Fields("MesicNovy") = IIf(IsNull(rst.Fields("MesicNovy")), Null, rst.Fields("MesicNovy"))
        .Fields("DenNovy") = IIf(IsNull(rst.Fields("DenNovy")), Null, rst.Fields("DenNovy"))
        .Fields("CharVyskyt") = IIf(IsNull(rst.Fields("CharVyskyt")), Null, rst.Fields("CharVyskyt"))
        .Fields("KatastrAutoID") = IIf(IsNull(rst.Fields("KatastrAutoID")), Null, rst.Fields("KatastrAutoID"))
        .Fields("OkresAutoID") = IIf(IsNull(rst.Fields("OkresAutoID")), Null, rst.Fields("OkresAutoID"))
        .Fields("RegionAutoID") = IIf(IsNull(rst.Fields("RegionAutoID")), Null, rst.Fields("RegionAutoID"))
        .Fields("Kvadrat") = IIf(IsNull(rst.Fields("Kvadrat")), Null, rst.Fields("Kvadrat"))
        .Fields("OblastAutoID") = IIf(IsNull(rst.Fields("OblastAutoID")), Null, rst.Fields("OblastAutoID"))
        .Fields("Lokalita") = IIf(IsNull(rst.Fields("Lokalita")), Null, rst.Fields("Lokalita"))
        .Fields("Zdroj") = IIf(IsNull(rst.Fields("Zdroj")), Null, rst.Fields("Zdroj"))
        .Fields("Pocet") = IIf(IsNull(rst.Fields("Pocet")), Null, rst.Fields("Pocet"))
        .Fields("Elevation") = IIf(IsNull(rst.Fields("Elevation")), Null, rst.Fields("Elevation"))
        .Fields("Poznamka") = IIf(IsNull(rst.Fields("Poznamka")), Null, rst.Fields("Poznamka"))
        .Fields("ProtokolCislo") = IIf(IsNull(rst.Fields("ProtokolCislo")), Null, rst.Fields("ProtokolCislo"))
        .Fields("ProtokolRok") = IIf(IsNull(rst.Fields("ProtokolRok")), Null, rst.Fields("ProtokolRok"))
        .Update
    End With
End With
Form_Data.Dirty = True
Form_Data.SetBrdrsVisible True
End Sub
Here's the code to make the label borders visible or not. Earlier I tried changing the border style to transparent, when that didn't work, I tried changing the border color to same as the form background, but that isn't working either. This exact routine, when called from the update events, either Before or After, works fine, but when called from the OnCurrent event, simply refuses to work. Breakpoints set, code pauses, I step through something like

lblElevation.BorderColor = i

and examine the value of lblElevation.BorderColor immediately after in the immediate window - it has NOT been set to i. Even when I execute that exact command in the immediate window, it has no effect, if I do it from within the bounds of the paused OnCurrent event code. Called from anywhere else, it works fine.

Code:
Public Sub SetBrdrsVisible(vis As Boolean)
Dim i&
i = IIf(vis, ShowBorder, HideBorder) ' Constants from Global module.
cboDruh.Controls(0).BorderColor = i
cboKatastr.Controls(0).BorderColor = i
lblKvadrat.BorderColor = i
lblElevation.BorderColor = i
cboOblast.Controls(0).BorderColor = i
txtLokalita.Controls(0).BorderColor = i
lblOd.BorderColor = i
lblDo.BorderColor = i
lblChrVyskyt.BorderColor = i
txtZdroj.Controls(0).BorderColor = i
txtZapsal.Controls(0).BorderColor = i
txtZapsano.Controls(0).BorderColor = i
lblPocet.BorderColor = i
lblProtokol.BorderColor = i
txtPoznamka.Controls(0).BorderColor = i
End Sub
pdanes is offline   Reply With Quote
Old 04-14-2011, 05:20 AM   #13
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,312
Thanks: 11
Thanked 719 Times in 669 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Change display in OnCurrent event not working

I think the reason that the Form_AfterUpdate and Form_BeforeUpdate events aren't firing is simple; you aren't creating a new record in the form!

You using a DAO recordset to add a new record directly in the underlying table, and this won't fire those events.

Have to say I've never seen a lot of copy function hacks and I've never see one constructed this way. Most use some variations of the following:

To copy all of a record
Code:
Private Sub CopyCompleteRecordl_Click()
 DoCmd.RunCommand acCmdSelectRecord
 DoCmd.GoToRecord , , acNewRec
 DoCmd.RunCommand acCmdPaste
End Sub
To only copy parts of a record
Code:
Private Sub CopyPartiaRecordl_Click()
'Copy fields from original record to variables
NewField1 = Me.YourField1
NewField2 = Me.YourField2
NewField3 = Me.YourField3

'Go to a new record
DoCmd.GoToRecord , , acNewRec

'Plug in old values from variables into new record
Me.YourField1.Value = NewField1
Me.YourField2.Value = NewField2
Me.YourField3.Value = NewField3

End Sub
Using either of these will fire the form's AfterUpdate and BeforeUpdate events.

Linq ;0)>
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 04-14-2011, 06:23 AM   #14
pdanes
Newly Registered User
 
Join Date: Apr 2011
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
pdanes is on a distinguished road
Re: Change display in OnCurrent event not working

Quote:
Originally Posted by missinglinq View Post
I think the reason that the Form_AfterUpdate and Form_BeforeUpdate events aren't firing is simple; you aren't creating a new record in the form!
Yes, thank you, I've used those other methods as well. Just thought I'd try something different here, and it works quite well. The addition of the

Form_Data.Dirty = True

statement also forces the update events to fire when navigating away, so I have something that works, either way. But I'm still at a loss as to why the code refuses to work in the OnCurrent event. The event fires, when another record is loaded. I can set breakpoints in the event code, step the code, but the given commands simply don't do anything. Can you think of anything that might be causing that?

pdanes is offline   Reply With Quote
Reply

Tags
display , event , oncurrent

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form OnCurrent event bug? morsagmon Forms 15 04-20-2010 09:00 PM
OnCurrent Event aziz rasul Modules & VBA 4 10-16-2007 12:33 AM
OnCurrent event FionaCondon Forms 9 09-15-2005 01:06 AM
Linked subform with oncurrent event mrlw00r Forms 4 07-01-2003 12:24 PM
MainForm's OnCurrent Event Lamb2087 Forms 4 02-13-2003 03:15 PM




All times are GMT -8. The time now is 08:54 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World