Ctrl Minus revistited

G

grumtac

I came across this old message without an answer:
I have a situation where I must prevent usage of CTRL + - ( CTRL &
Minus Sign ) shortcut, which deletes current record. Is there any way
to do this..........

Is it true that there is no way at all to disable or redirect the Ctrl-
(minus) key events ?

If so, I can't believe they (developers) would have allowed that so
close to the common Print key stroke, Ctrl-P. They must not have had
any "bifocal" wearing developers, or "todays typists".

Some of the forms that we have pop up on the way to printing require a
few Ctrl-P's, so users automatically just hit what they think is Ctrl-P
a few times..... Losing of course a handful of records without ANY
warning because they hit Ctrl Minus.

If anyone knows of any software method to intercept the Ctrl Minus Key
combo in Access 97, please let me know. I am getting to the point where
I will be physically disabling the Minus key on all of our Keyboards.

Also, is this typical to ALL of the subsequent newer versions of Access
?

Thanks,
Chris L
 
A

Albert D. Kallal

First, a few things:

If you select the record selction,k and hit the del key, hten you DO GET A
PROMTP asking to confirm deleation of the roecrd.

If you go edit->deletec reocrd, then YOU DO GETA APROMPT asking to conirrm
delation of the 4roecrd.

And, if yu hit ctrl-:"-", thne YOU DO GET A PROMPT asking to covni er dlaong

I can't iamong any devlepoer with ANY AMOUNT of compality would diable the
promtps in ms-access. If you are NOT geting a conform prompt, then someone
REALLY REALLY scruped up the setitng in your appciton.

You can of couse trap any keystrop on a form, but this kind of belabours the
pront I make above that your code, and desings should prvent the user from
delering a reocrd.

You mean you want to diable the ctrl-"-" key, but not worry about the other
zillion possbiel ways of deleing the roecrd? This is just the wrong aprpaoch
all around. If you don't wan users to delete a reocrd, then you need to code
as such in forms "before del conform" evnet, or the useal forms "delete
event".

If your form is not prompting now..then likey someone has turned off
setwarings...but that deables ALL prompts for confing delaring, that just
don't fly with any compemnt system (or devglorer!!).

Anway, if you do want to trap some keys for a form, you can use the fomrs
keydown event, and set the forms key preview = yes.

The code to trp the ctr-"-" key would be:


If (Shift And acCtrlMask) > 0 Then
If KeyCode = 189 Then
KeyCode = 0
End If
End If

So, you can most certanly build your own key handerles for a form, and I
OFTEN do this for continues forms, as I want the up/down arrows to work like
a data sheet, and the enter key often will "launch open" a details form. The
key hand to do this looks like:

If KeyCode = vbKeyReturn Then
KeyCode = 0
if isnull(me.id) then
docmd.OpenForm "frmCustomer",,,"id = " & me.id
endif
End If

If KeyCode = vbKeyDown Then
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acNext
End If

If KeyCode = vbKeyUp Then
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acPrevious
End If

End Sub

Anyway, while the above shows that you have much flexibility in terms of
trapping keys, you REALLY REALLY need to fix, or address as to why NO prompt
is occurring when the user hits ctrl-"-". If there is not prompt for that
key sequence, then using edit->delete record, or highlighting the record
selection and hitting the del key will also delete the record without a
prompt. It seems to me, your problem is FAR FAR removed from ctrl-"-", but
in fact some one incompetent situation that is allowing the record delete to
run without a prompt....
 
J

John Webb via AccessMonster.com

You have several options, assuming that users will only have access to your
data via forms:

option 1:

Change the form properties so that it does not allow deletions.
This option is not acceptable for most applications thou, as we normally
want to give the end user the option of deleting records.

Option 2:
Intercepting the keyboard shortcuts with an event procedure.

attach the following to your form keydown event:

***CODE BEGINS***

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If Shift = acCtrlMask And _
(KeyCode = vbKeySubtract Or KeyCode = 189) Then KeyCode = 0

End Sub

***CODE ENDS***

Ensure that they KeyPreview option on your form is set to yes.

This should stop the problem

Cheers

John Webb
 
A

Albert D. Kallal

geesh...lets try this again with the spell checker!! (phone rang...bumped
send!!)

First, a few things:

If you select the record selector, and hit the del key, then you DO GET A
PROMPT asking to confirm deletion of the record.

If you go edit->delete record, then YOU DO GET A PROMPT asking to confirm
deletion of the record.

And, if you hit ctrl-:"-", then YOU DO GET A PROMPT asking to confirm
deletion again

I can't imagine any developer with ANY AMOUNT of competence would disable
the
prompts in ms-access. If you are NOT getting a confirm prompt, then someone
REALLY REALLY screwed up the setting in your application.

You can of course trap any key stroke on a form, but this kind of belabors
the
point I make above that your code, and designs should prevent the user from
deleting a record.

You mean you want to disable the ctrl-"-" key, but not worry about the other
zillion possible ways of deleing the record? This is just the wrong approach
all around. If you don't wan users to delete a record, then you need to code
as such in forms "before del conform" event, or the usual forms "delete
event".

If your form is not prompting now..then likely someone has turned off
setwarnings...but that disables ALL prompts for confirm deleting, that just
don't fly with any competent system (or developer!!).

Anyway, if you do want to trap some keys for a form, you can use the forms
keydown event, and set the forms key preview = yes.

The code to trap the ctr-"-" key would be:


If (Shift And acCtrlMask) > 0 Then
If KeyCode = 189 Then
KeyCode = 0
End If
End If

So, you can most certainly build your own key handlers for a form, and I
OFTEN do this for continues forms, as I want the up/down arrows to work like
a data sheet, and the enter key often will "launch open" a details form. The
key hand to do this looks like:

If KeyCode = vbKeyReturn Then
KeyCode = 0
if isnull(me.id) then
docmd.OpenForm "frmCustomer",,,"id = " & me.id
endif
End If

If KeyCode = vbKeyDown Then
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acNext
End If

If KeyCode = vbKeyUp Then
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acPrevious
End If

End Sub

Anyway, while the above shows that you have much flexibility in terms of
trapping keys, you REALLY REALLY need to fix, or address as to why NO prompt
is occurring when the user hits ctrl-"-". If there is not prompt for that
key sequence, then using edit->delete record, or highlighting the record
selection and hitting the del key will also delete the record without a
prompt. It seems to me, your problem is FAR FAR removed from ctrl-"-", but
in fact some one incompetent situation that is allowing the record delete to
run without a prompt....
 
J

John Webb via AccessMonster.com

Albert,

What you state is not necessarily true; Access has an option to disable the
prompts for deleting records. If this has been disabled then the end user
will not recieve any messages.

This is not down to flawed design. I would suggest you remove yourself
from your high horse!

However, you are correct that other methods of deleting records should be
accounted for. You can interrupt for the delete key (vbkeyDelete), and not
allow access to shortcut menus etc.

However, another approach would be to set a boolean variable in your form,
and upon loading the form set this false.
You will need to set this value to True on your "delete" record button, and
back to false once the record has been deleted.
Then simply perform a test in your Form_Delete event:

***CODE BEGINS***

Private Sub Form_Delete(Cancel As Integer)
cancel = not blnDelete
End Sub


***CODE ENDS***

This would eliminate the need for handling the many ways of deleting
records, by simply setting a flag to say when you are allowing a delete
function to be carried out.

Hope that helps

John Webb
 
G

grumtac

Albert said:
geesh...lets try this again with the spell checker!! (phone rang...bumped
send!!)

Albert,
For a minute there I thought you may have had your Keycaps off your
keyboard for cleaning, and then got them mixed up when you put them
back on ! <G> This actually was the case with a fellow in another
group, but only with a letter or two. One of the really smart guys in
that group saw the routine error and brought it to the guys attention.

Anyhow,.....
And, if you hit ctrl-:"-", then YOU DO GET A PROMPT asking to confirm
deletion again

When I first go into one of the forms in particular, a form with
multiple tabbed pages, I will at first get the small message in the
footer bar that says " Records can't be deleted with this form" when
hitting Ctrl "-". But if I go to a different tabbed page and then back
to the first, that same key command will suddenly allow deletion, not
only of that record, but it will continue to delete subsequent records
ever time I use the Key combo.
I can't imagine any developer with ANY AMOUNT of competence would disable
the
prompts in ms-access. If you are NOT getting a confirm prompt, then someone
REALLY REALLY screwed up the setting in your application.

This happens to be the accounting/inventory development from database
creations called "Yes I can" (Cary Prauge ?), however it has been very
much modified at this point, so it could have crept in somewhere. It
would take me some jumping thru hoops to see if the original app did
the same thing.

Users mostly complained about the loss of records in one primary area,
but as I played around with it since I posted, it almost seems that
only SOME forms will allow deletion without any warning, and once it
does that, then it will continue to delete as I mentioned above.
Leaving the form and coming back in seems to require one to go to one
of the tabbed pages and do the delete, then it deletes at anytime
anywhere in the form, on any tabbed page. This will take me a little
time to compare tabbed page settings and see if there are some that are
missing something.
You mean you want to disable the ctrl-"-" key, but not worry about the other
zillion possible ways of deleing the record? This is just the wrong approach
all around.

Basically, all the forms have "Delete" buttons that we do not tab to.
My thinking was that IF your going to delete a record, Your going to
have to take your mouse willingly over the button and click it.
Otherwise I have been a real stickler for using Tab to go from field to
field, as it dictates the order we need to run this business. All of
the Delete buttons work perfectly and with warning, so, Supergluing the
"-" key in the up position really would not be a problem if thats what
it came to. I am confident that users could learn where the other "-"
key is, and then I wouldn't have the Ctrl-P "accidents.
The code to trap the ctr-"-" key would be:
If (Shift And acCtrlMask) > 0 Then
If KeyCode = 189 Then
KeyCode = 0
End If
End If

I think this "189" was what I was looking for. I couldn't find that
yesterday, and I will explore your samples use after I first look at
each tabbed page and why it currently does what it does.

Thanks for having a go at this. I'm really a newbie, having no formal
training, but only the last 3 years in and out, modifying areas mostly
by examining code used in other areas, or trial and error.

I will explore this more, and will likely post back what I find.

Thanks,
Chris L
 
G

grumtac

John said:
You have several options, assuming that users will only have access to your
data via forms:

option 1:

Change the form properties so that it does not allow deletions.
This option is not acceptable for most applications thou, as we normally
want to give the end user the option of deleting records.

Option 2:
Intercepting the keyboard shortcuts with an event procedure.

attach the following to your form keydown event:

***CODE BEGINS***

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If Shift = acCtrlMask And _
(KeyCode = vbKeySubtract Or KeyCode = 189) Then KeyCode = 0

End Sub

***CODE ENDS***

Ensure that they KeyPreview option on your form is set to yes.

This should stop the problem

Thank you John for that example code. I have a feeling that this will
be a viable option on the forms this is happening with. I first want to
do some in depth research, as I indicated in another post, the first
and last tabbed page of one form I have, will not allow deletion via
the key commands in question, but, If I go to some tabbed pages in the
middle of the same form, it will "Start" the delete routine such that
if one continues hitting the Ctrl - keys, it will continue to delete
subsequent records from ANY tabbed view. Only leaving the form and
returning will put one back at the beginning of this issue.

Before I "leap", I am going to have a good "look", and both you and
Albert have really brought that to my attention.

Thanks !

Chris L
 
D

Dirk Goldgar

Albert,
For a minute there I thought you may have had your Keycaps off your
keyboard for cleaning, and then got them mixed up when you put them
back on ! <G>

LOL

I read that post, and wondered if Albert had been sniffing glue or
something.
When I first go into one of the forms in particular, a form with
multiple tabbed pages, I will at first get the small message in the
footer bar that says " Records can't be deleted with this form" when
hitting Ctrl "-". But if I go to a different tabbed page and then back
to the first, that same key command will suddenly allow deletion, not
only of that record, but it will continue to delete subsequent records
ever time I use the Key combo.

From the sound of it, some code or macro associated with the other tab
page or with the tab control itself is turning warnings off and not
turning them back on again. Look for code that says

DoCmd.SetWarnings False

or a macro that invokes the SetWarnings action. People often turn off
warnings when executing an action query in code, but then they must be
sure to turn them back on again. Sometimes they overlook a logic path
(often in error-handling) that allows execution to work its way out of a
procedure without executing the statement that turns warnings back on.
 
G

grumtac

Dirk said:
From the sound of it, some code or macro associated with the other tab
page or with the tab control itself is turning warnings off and not
turning them back on again. Look for code that says

DoCmd.SetWarnings False

or a macro that invokes the SetWarnings action. People often turn off
warnings when executing an action query in code, but then they must be
sure to turn them back on again.

Dirk,
Thank you for your help as well. I will double check for any use of the
code as you suggest. That would be another way this could be happening.

Thanks,

Chris L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top