NeoPa 32,556
Expert Mod 16PB
I have form which handles Shift-Esc by calling a close of the form (See line #6 below). - Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
-
If (Shift And acShiftMask) <> acShiftMask Then Exit Sub
-
On Error Resume Next
-
Select Case KeyCode
-
Case vbKeyEscape
-
Call DoCmd.Close
-
Case vbKeyUp
-
Call DoCmd.GoToRecord(Record:=acPrevious)
-
Case vbKeyDown
-
Call DoCmd.GoToRecord(Record:=acNext)
-
End Select
-
End Sub
Although identical code works fine from my cmdExit button, whenever this executes (from within the KeyDown event procedure) it causes the application (Access) to exit completely.
I'd be interested to hear of anything that can throw any light on the matter.
Running Access 2000 on Windows 2000 Server.
18 1982
Don't know what to tell you, Ade, it works as advertised for me! I can only duplicate the behavior by putting DoCmd.Quit in the form's Form_Close event.
Sorry!
Linq ;0)>
Hi, Adrian.
It is really weird. I have only a couple of guesses. - did you try to explicitely pass form name as argument to DoCmd.Close method?
- is there any code in OnClose event handler?
- in step mode, does Access crash immediately after executing DoCmd.Close?
- what will happen if you disable error trapping?
Regards,
Fish
I have form which handles Shift-Esc by calling a close of the form (See line #6 below). - Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
-
If (Shift And acShiftMask) <> acShiftMask Then Exit Sub
-
On Error Resume Next
-
Select Case KeyCode
-
Case vbKeyEscape
-
Call DoCmd.Close
-
Case vbKeyUp
-
Call DoCmd.GoToRecord(Record:=acPrevious)
-
Case vbKeyDown
-
Call DoCmd.GoToRecord(Record:=acNext)
-
End Select
-
End Sub
Although identical code works fine from my cmdExit button, whenever this executes (from within the KeyDown event procedure) it causes the application (Access) to exit completely.
I'd be interested to hear of anything that can throw any light on the matter.
Running Access 2000 on Windows 2000 Server.
Hello NeoPa, like our esteemed colleague linq has stated - It works as advertised for me! I am leaning along the lines of our other esteemed colleague, FishVal in that although the code works as intended, the Unload(), Deactivate(), and Close() Events of the Form are obviously fired in that sequence. Anything in either one of those Events that cause cause an Exit from Access?
I have form which handles Shift-Esc by calling a close of the form (See line #6 below). - Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
-
If (Shift And acShiftMask) <> acShiftMask Then Exit Sub
-
On Error Resume Next
-
Select Case KeyCode
-
Case vbKeyEscape
-
Call DoCmd.Close
-
Case vbKeyUp
-
Call DoCmd.GoToRecord(Record:=acPrevious)
-
Case vbKeyDown
-
Call DoCmd.GoToRecord(Record:=acNext)
-
End Select
-
End Sub
Although identical code works fine from my cmdExit button, whenever this executes (from within the KeyDown event procedure) it causes the application (Access) to exit completely.
I'd be interested to hear of anything that can throw any light on the matter.
Running Access 2000 on Windows 2000 Server.
Back again, NeoPa. Your gonna love this one. If your SHIFT+ESC sequence is off, namely if you press these Keys almost simultaneously, and it you have the Escape Property of a Command Button with a DoCmd.Quit in its Click() Event, you will exit Access and not just the Form. I know it's far fetched, but you must admit that it is a weird problem. (LOL).
NeoPa 32,556
Expert Mod 16PB
Right, I'm a bit limited for time right now (at work) so I'll just say that I will reply in more detail later. I appreciate all of your attention though.
Opening and closing of forms in my database is captured by a generic Form class module. This may well be the root of the problem, but I will explore more later (and post my findings of course).
@ADezii
I don't have that but I do have a similar button that simply closes the form. As it's in "Continuous Forms" mode though, the Escape key is unable to trigger from this. It's actually what I'm trying to reproduce. As I say though, only to close the form.
PS. I'll post the current version of my whole module simply for reference, but the code has changed in the procedure we're talking about.
NeoPa 32,556
Expert Mod 16PB
Reference Post: - Option Compare Database
-
Option Explicit
-
-
Private strJob As String
-
Private intOption As Integer
-
-
Private Sub Form_Open(Cancel As Integer)
-
With Me
-
strJob = ""
-
If .Filter > "" Then strJob = Split(.Filter, "'")(1)
-
.Caption = Replace(.Caption, "%J", strJob)
-
.lblTitle.Caption = Replace(.lblTitle.Caption, "%J", strJob)
-
.txtJob.DefaultValue = "'" & strJob & "'"
-
Call SetDefaultStep
-
End With
-
End Sub
-
-
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
-
If (Shift And acShiftMask) <> acShiftMask Then Exit Sub
-
'In case record navigation goes beyond start/end of .Recordset
-
On Error Resume Next
-
Select Case KeyCode
-
Case vbKeyEscape
-
Call Me.cmdExit.SetFocus
-
Case vbKeyUp
-
Call DoCmd.GoToRecord(Record:=acPrevious)
-
Case vbKeyDown
-
Call DoCmd.GoToRecord(Record:=acNext)
-
End Select
-
End Sub
-
-
Private Sub Form_AfterInsert()
-
Call SetDefaultStep
-
End Sub
-
-
Private Sub SetDefaultStep()
-
Me.txtStep.DefaultValue = Nz(DMax("[Step]", _
-
"[tblJobTask]", _
-
"[Job]='" & strJob & "'"), 0) + 1
-
End Sub
-
-
Private Sub cmdSwitch_Click()
-
Dim blnOptionA As Boolean
-
-
With Me
-
blnOptionA = (Not .lblJob.Visible)
-
.lblJob.Visible = blnOptionA
-
.lblStep.Visible = blnOptionA
-
.lblType.Visible = blnOptionA
-
.lblTask.Visible = blnOptionA
-
.lblMRFrom.Visible = Not blnOptionA
-
.lblMRTo.Visible = Not blnOptionA
-
.lblMsg.Visible = Not blnOptionA
-
.txtJob.Visible = blnOptionA
-
.txtStep.Visible = blnOptionA
-
.txtType.Visible = blnOptionA
-
.txtTask.Visible = blnOptionA
-
.txtMRFrom.Visible = Not blnOptionA
-
.txtMRTo.Visible = Not blnOptionA
-
.txtMsg.Visible = Not blnOptionA
-
If blnOptionA Then
-
Call .txtStep.SetFocus
-
Else
-
Call .txtMsg.SetFocus
-
End If
-
End With
-
End Sub
-
-
Private Sub cmdDelete_Click()
-
With Me
-
If Not IsNull(.txtJob) Then
-
'We allow for cancellation by operator
-
On Error Resume Next
-
Call DoCmd.RunCommand(acCmdDeleteRecord)
-
On Error GoTo 0
-
Call SetDefaultStep
-
End If
-
Call .txtStep.SetFocus
-
End With
-
End Sub
-
-
Private Sub cmdExit_Click()
-
Call DoCmd.Close
-
End Sub
-
-
Private Sub Form_Close()
-
'Method must exist in order for container to handle event.
-
End Sub
NeoPa 32,556
Expert Mod 16PB
...
@ADezii
I don't have that but I do have a similar button that simply closes the form. As it's in "Continuous Forms" mode though, the Escape key is unable to trigger from this. It's actually what I'm trying to reproduce. As I say though, only to close the form.
...
Not quite correct - I had to set the Cancel property to False on that button as it was triggering when I simply wanted to cancel an amendment. Normally my cmdExit buttons have it set to True.
Hello NeoPa, there are a couple of conventions that you frequently use that I am a little confused on, and also curious about. I am specifically referring to the two items listed below. If you don't mind, can you please explain the logic: - Case 1==> ([use of (1)] ==> Split(.Filter, "'")(1)
- Case 2 ==> [Replaceable Parameters]?
-
.Caption = Replace(.Caption, "%J", strJob)
-
.lblTitle.Caption = Replace(.lblTitle.Caption, "%J", strJob)
- Thanks for bearing with me.
NeoPa 32,556
Expert Mod 16PB
Update:
I tried adding the close in on the KeyUp event, but still had the same problem :(
NeoPa 32,556
Expert Mod 16PB
Hello NeoPa, there are a couple of conventions that you frequently use that I am a little confused on, and also curious about. I am specifically referring to the two items listed below. If you don't mind, can you please explain the logic:- Case 1==> ([use of (1)] ==> Split(.Filter, "'")(1)
- Case 2 ==> [Replaceable Parameters]?
-
.Caption = Replace(.Caption, "%J", strJob)
-
.lblTitle.Caption = Replace(.lblTitle.Caption, "%J", strJob)
- Thanks for bearing with me.
Certainly, as far as I am able. - I think the line you're referring to is :
- If .Filter > "" Then strJob = Split(.Filter, "'")(1)
The .Filter string would typically be something like :
[Job]='PriceUpd'
The Split() function returns an array (lowest element numbered 0) of string type variants where each of the characters in the string matching that supplied (') acts as a separator.
In this case an array would be created :
0 = "[Job]="
1 = "PriceUpd"
2 = ""
As with any array (including an array returned by a function), appending an index in parentheses selects that individual element.
So, Split(.Filter, "'")(1) == "PriceUpd" - When using strings with variable items in, I prefer to build it up in exactly that way. It makes it clearer to someone reading the code that there is a string required, and a part of it is variable (the %parameter bit) but that the main string is like a template and is unchanging. The data in both the .Caption and .lblTitle.Caption properties (See lines #11 to #12) is :
tblJobTask (%J)
So, from the earlier code - they are both set to :
tblJobTask (PriceUpd)
NB. The code was not provided with any expectation that anyone would try to debug from that. It is purely and simply for reference purposes. If anyone had any questions about what else was there, it may be answered simply by checking through the code.
Not sure how this might be happening with your situation, but when using the .Close method, if the optional objecttype and objectname arguments are left blank, Access closes the active window.
Is it possible that the focus is being passed from the form to the database window in your setup, thus causing the active window to be the database, which then is closed?
As a simple test you could try adding the objecttype and objectname arguments to see if that changes the behavior.
Regards,
Scott
Certainly, as far as I am able.- I think the line you're referring to is :
- If .Filter > "" Then strJob = Split(.Filter, "'")(1)
The .Filter string would typically be something like :
[Job]='PriceUpd'
The Split() function returns an array (lowest element numbered 0) of string type variants where each of the characters in the string matching that supplied (') acts as a separator.
In this case an array would be created :
0 = "[Job]="
1 = "PriceUpd"
2 = ""
As with any array (including an array returned by a function), appending an index in parentheses selects that individual element.
So, Split(.Filter, "'")(1) == "PriceUpd" - When using strings with variable items in, I prefer to build it up in exactly that way. It makes it clearer to someone reading the code that there is a string required, and a part of it is variable (the %parameter bit) but that the main string is like a template and is unchanging. The data in both the .Caption and .lblTitle.Caption properties (See lines #11 to #12) is :
tblJobTask (%J)
So, from the earlier code - they are both set to :
tblJobTask (PriceUpd) NB. The code was not provided with any expectation that anyone would try to debug from that. It is purely and simply for reference purposes. If anyone had any questions about what else was there, it may be answered simply by checking through the code.
Curiosity satisfied, thanks NeoPa.
NeoPa 32,556
Expert Mod 16PB
I'm afraid not Scott. This is definitely calling the close from within the form itself. The focus is in one of the bound controls when Shift-Esc is pressed.
As I only recently discovered (while working on this form) that I didn't need to include the ObjectType:=acForm and ObjectName:=Me.Name parameters if I was only interested in closing the current form, I have most of my code still with these parameters set. In this particular instance I did try both ways, for both the KeyDown event procedure and the cmdExit Click procedure.
It was worth checking, and I did. Unfortunately no joy there either.
NeoPa 32,556
Expert Mod 16PB
Curiosity satisfied, thanks NeoPa.
Anytime ADezii.
Did you find the reasoning made sense to you?
Do they sound like techniques you may want to take up?
NeoPa 32,556
Expert Mod 16PB
As an addendum to that, and only for anyone interested in such things, I actually find that I use the Replace() technique so much that I even wrote a function to handle multiple pairs of parameters for replacing.
I have to replace any posted code with multiple calls to Replace() so that it makes sense generally in the forums. - 'MultiReplace replaces all occurrences of varParam in strMain with varReplace.
-
'Using VbBinaryCompare means that case is not ignored.
-
Public Function MultiReplace(ByRef strMain As String, _
-
ByVal varParam As Variant, _
-
ByVal varReplace As Variant, _
-
ParamArray avarArgs())
-
Dim intIdx As Integer
-
-
If (UBound(avarArgs) - LBound(avarArgs)) Mod 2 = 0 Then Stop
-
MultiReplace = Replace(Expression:=strMain, _
-
Find:=Nz(varParam, ""), _
-
Replace:=Nz(varReplace, ""), _
-
Compare:=vbBinaryCompare)
-
For intIdx = LBound(avarArgs) To UBound(avarArgs) Step 2
-
MultiReplace = Replace(Expression:=MultiReplace, _
-
Find:=Nz(avarArgs(intIdx), ""), _
-
Replace:=Nz(avarArgs(intIdx + 1), ""), _
-
Compare:=vbBinaryCompare)
-
Next intIdx
-
End Function
Anytime ADezii.
Did you find the reasoning made sense to you?
Do they sound like techniques you may want to take up?
Did you find the reasoning made sense to you?
The reasoning made perfect sense to me, NeoPa
Do they sound like techniques you may want to take up?
I already made the change to single line Declarations, and eliminated all multi-line Statements, I guess anything is possible. (LOL).
NeoPa 32,556
Expert Mod 16PB
LOL - I like it ADezii :)
But I just remembered I haven't even done Fish the courtesy of replying properly to his post :(
I will get to it immediately.
NeoPa 32,556
Expert Mod 16PB
Hi, Adrian.
It is really weird. I have only a couple of guesses.- did you try to explicitely pass form name as argument to DoCmd.Close method?
- is there any code in OnClose event handler?
- in step mode, does Access crash immediately after executing DoCmd.Close?
- what will happen if you disable error trapping?
Regards,
Fish
- I did try that - it behaved in exactly the same way.
- Good question - I do have a class that encapsulates forms and handles un-hiding the calling form when the called one is closed. In that sense code IS run on closure of the form.
- Although I'm unable to test this now, I do know from running this after changes have been made to the design of the form, that the .Close method is in progress already (or even completed) as the Save Changes prompt comes up before the application disappears.
- Error trapping has now been disabled and the problem still exists.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: puzzlecracker |
last post by:
Fixed font - Proportional font
string initilization WHY?
All 2 messages in topic - view as tree
puzzlecracker Jan 29, 10:47 pm show options
Newsgroups: comp.lang.c
From:...
|
by: billmiami2 |
last post by:
We are having trouble with an MS Access 2000 application. The
application is set up in the standard fashion with a database mdb and a
user interface mdb with links from the user to the data file. ...
|
by: Ricardo Pereira |
last post by:
Hello all,
I have a C# class (in this example, called A) that, in its
constructor, starts a thread with a method of its own. That thread
will be used to continuously check for one of its...
|
by: Marty Cruise |
last post by:
I am getting the following error: " Object reference not
set to an instance of an object."
The strange thing is that I AM creating a new instance of
the object in the PageLoad event Iin the code...
|
by: jsimons |
last post by:
If the user accidentally clicks the X close button I'm using the
following code in the form unload event to stop them from accidentally
quitting Access.
Private Sub Form_Unload(Cancel As...
|
by: =?Utf-8?B?am9uZWZlcg==?= |
last post by:
I have a simple Login page that suddenly is producing this error.
What is perplexing is that I didn't touch this page or anything (that I can
think of that is related)
All I did was make another...
|
by: dstork |
last post by:
Anyone know how to rename the "Exit Access" command at the bottom of
the Office menu. I'd like to rename it to "Exit" as I had done in
previous versions of Access. I know I can disable it with
...
|
by: resqtech |
last post by:
I am having an issue with an Access Database that worked at one time and after a Windows Update that screwed up the profile it stopped working. The following is what VB is stating causes the error. ...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |