472,811 Members | 1,143 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 software developers and data experts.

"Object invalid or not set" error message - related to trapping the Escape key???

I have an Access 2000 database with a form that is giving me some
major headaches. When you open the form, it displays all records and
allows editing, but has AllowAdditions set to False so that the user
has to use my New Record button. When you click the New Record
button, the form presents a new record for editing. My client wants
to use the Escape key to cancel changes to new or existing records.
On existing records, Access already handles this - hitting the Escape
key cancels changes and redisplays the record without your changes.
However, on a new record, hitting the Escape key in form view doesn't
do anything. So, I'm trapping the Escape key in the Form_KeyDown
event, and then calling some code to discard the new record and return
the form to view/edit mode.

Here's where things get interesting. If you open the form, click the
New button, and then hit the Escape key, the form does everything it's
supposed to do, but as soon as you move to a different record with the
navigation keys, you get the error message "Object invalid or not
set". Actually the message pops up twice, one right after the other.
This behavior happens very consistently.

Now, after digging through the Microsoft knowledge base, searching
through all the newsgroup postings on this error, decompiling my
database, and installing the latest service pack, I still haven't
found the solution, but I have found a curious workaround.

If I instead put a Cancel button on the form instead of trapping the
Escape key, and run the exact same code when it's clicked, the error
goes away. So, why not just leave it that way, you ask? Well, I just
may if my client can bend a little. But it's a little scary to think
that the Escape key actually caused the problem. I'm concerned that
something else is to blame here and that it may manifest itself under
different circumstances.

Here's some code in case anyone has some ideas on why the error occurs
when I trap the Escape key:

' Undo all record editing and switch to view/edit mode if we are in
new record mode.
Private Sub CancelChanges()
If mbooNewRecord Then
Me.Recordset.CancelUpdate
mbooNewRecord = False
Me.Recordset.MoveLast
' Synchronize the form bookmark with the recordset bookmark.
Me.Bookmark = Me.Recordset.Bookmark
ViewModeSetup
End If
End Sub

' Configure buttons for new record mode.
Private Sub NewModeSetup()
' Move focus off the New button before disabling it.
[Cust Name].SetFocus
' Clear these unbound combo boxes.
[Cust Name].Value = ""
[Client Name].Value = ""
[Referral Name].Value = ""
[Referral Name].Enabled = False
[Water Type].Enabled = False
cmdNew.Enabled = False
cmdJobList.Enabled = False
cmdDuplicate.Enabled = False
cmdRelatedJobs.Enabled = False
Me.NavigationButtons = False
End Sub

' Configure buttons for record viewing/editing mode.
Private Sub ViewModeSetup()
cmdNew.Enabled = True
cmdJobList.Enabled = True
Me.NavigationButtons = True
Me.AllowAdditions = False
End Sub

Private Sub cmdNew_Click()
DoCmd.RunCommand acCmdSaveRecord ' Save any pending changes
first.
NewModeSetup
Me.AllowAdditions = True
mbooNewRecord = True
Me.Recordset.AddNew
End Sub
The error occurs when this code is executed in response to hitting the
Escape key:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim lctlCurControl As Control

' F2 key activates the contact view/edit form.
If KeyCode = vbKeyF2 Then
ViewContact
' F3 key activates the contact list.
ElseIf KeyCode = vbKeyF3 Then
On Error GoTo NoActiveControl
Set lctlCurControl = Screen.ActiveControl
If lctlCurControl.Name = "Client Name" Then
Client_Lookup
ElseIf lctlCurControl.Name = "Referral Name" Then
Referral_Lookup
Else
NoActiveControl:
Customer_Lookup
End If
ElseIf KeyCode = vbKeyEscape Then
KeyCode = 0 ' Cancel the keystroke.
CancelChanges
End If
End Sub
The error doesn't occur when the following code is run is response the
clicking the Cancel button:

Private Sub cmdCancel_Click()
CancelChanges
End Sub
Also note that I've tried creating and discarding the new record using
DoCmd.RunCommand and DoCmd.MenuItem without any change in behavior.
I've also tried not cancelling the Escape keystroke in the KeyDown
event. In reference to knowledge base articles, I'm not attaching to
any Oracle tables, and I'm always setting a local variable to
CurrentDb before referencing any properties or methods of it.

Any thoughts on the problem are greatly appreciated.

Paul
Nov 12 '05 #1
3 4511
"Paul" <pa*******@comcast.net> wrote in message
news:9c**************************@posting.google.c om...
I have an Access 2000 database with a form that is giving me some
major headaches. When you open the form, it displays all records and
allows editing, but has AllowAdditions set to False so that the user
has to use my New Record button. When you click the New Record
button, the form presents a new record for editing. My client wants
to use the Escape key to cancel changes to new or existing records.
On existing records, Access already handles this - hitting the Escape
key cancels changes and redisplays the record without your changes.
However, on a new record, hitting the Escape key in form view doesn't
do anything.


You lost me at this point, Paul.

The Esc key (or Undo from the Edit menu) should undo a new record.
It might be good to see why this is not happening.
You should also get the Form_Undo event at this point.

--
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.
Nov 12 '05 #2
Allen,

Thanks for your reply. You're right - the Escape key does undo changes
to the new record, but it leaves you on a blank form. My intention here
is to take the user out of the new record completely and return to the
last record in the recordset.

Also, I don't see that there's any such thing as a Form_Undo event. Am
I missing something here?

Paul

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
Rats! You said Access 2000. Form_Undo was introduced in 2002.

--
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.

"Paul Angelino" <pa*******@comcast.net> wrote in message
news:3f*********************@news.frii.net...
Thanks for your reply. You're right - the Escape key does undo changes
to the new record, but it leaves you on a blank form. My intention here
is to take the user out of the new record completely and return to the
last record in the recordset.

Also, I don't see that there's any such thing as a Form_Undo event. Am
I missing something here?

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: deko | last post by:
I'm getting intermittent "Object Invalid or No Longer Set" errors in my Access 2002 mdb. What causes these errors? Has anyone dealt with this before? I can't trace it because it's not easy...
6
by: Lauchlan M | last post by:
Hi. Usin ASP.NET, getting an "Object reference not set to an instance of an object" error. In my login.aspx page I have: string arrUserRoles = new string {"UserRole"};...
2
by: Steph. | last post by:
How can I make a "ModalObject" that will react like a ModalForm ? I mean an object that will run in it's own message loop and return a value (a string value) when closed. Example : ...
1
by: Kamal | last post by:
I am trying to send mail through smtp. smtp service is running on my machine. But every time during the smtpmail.send(msg) call gives "Could not access 'CDO.Message' object." error. Could some...
1
by: Lauchlan M | last post by:
Hi. I'm using ASP.NET, getting an "Object reference not set to an instance of an object" error. In my login.aspx page I have: string arrUserRoles = new string {"UserRole"};...
7
by: dhnriverside | last post by:
Hi peeps I'm just following this HOW-TO from MSDN.. http://support.microsoft.com/default.aspx?scid=kb;en-us;306355 But I've got a problem. I've adding the #using System.Diagnostics; line to...
2
by: louie.hutzel | last post by:
This JUST started happening, I don't remember changing any code: When I click the submit button on my form, stuff is supposed to happen (which it does correctly) and a result message is posted back...
3
by: FelixSmith | last post by:
I have recently posted a new access database and its oracle tables onto a shared folder for various users. It is a search database and me and a few other users are able to pull from the file and use...
5
by: piyumi80 | last post by:
hi, i write the following code to get a specific data row from the data set.but it generates the "Object reference not set to an instance of an object.".....error private void...
1
tlhintoq
by: tlhintoq | last post by:
I'm pretty sure this is language independent and is going to be the same whether it's VC or C# - but my project is C# WIndows Forms just in case. Does anyone have a good handle on the sequence of...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.