• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Hot keys dont work when a form has no records

Access 2007: I have form for entering Sales Order details. In the form header there are several command buttons which allow the user to navigate to different records and also to perform tasks related to the current sales order. All the command buttons have hot keys assiged to them by putting an ampersand in the caption property.

My problem is that the hotkeys do not work when there are no records present in the detail section. For instance, I have an 'New &item' button which invokes a wizard to add a new item to the Sales Order. Currently, this hot key only works if there are already some items in the current Sales Order. When the user wishes to add the first record, he has to explicitly click the button.

It's not the end of the world that this happens, but it's not easy to get people using hot keys when they only work some of the time. I know I can use the Keydown event to trap keystokes as they occur. But it would be nice to get the hotkeys working properly.

Ian
0
TownTalk
Asked:
TownTalk
  • 5
  • 3
  • 3
  • +1
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
That's odd. A Hotkey simply "runs" the code associated with the click event of the object, so IF you can click that button and your code runs fine, then the Hotkey should do so as well.

Have you tried performing maintenance on the database? Try a Compact (Office button - Manage - compact), and also make sure that Office/Access and Windows are fully up to date.
0
 
TownTalkAuthor Commented:
Yes, Everything is up to date and I compact and repair regularly.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You might try changing the hotkey combination temporarily to see if that works - for example, set the caption to "New I&tem" and see if the "&t" hokey combination works. If it does, you might delete and recreate the button (make sure to save the code behind it first, in case Access decides to remove that code).
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hnasrCommented:
Attach a sample form showing the problem.
0
 
TownTalkAuthor Commented:
Ok I tried those things and it made no difference. I should emphasise however that there are several buttons on this form and their hotkeys all stop working at the same time. I've noticed the same behavior on other forms also. However I have noticed now that the hotkeys will work once when there are no records, then they dont work again.

To prove a point, a just created a brand new form. I put a command button in the header with an Event Handler that writes the system time into the form caption.  I then gave this form a recordset that returns records and the hotkey worked fine.  I then changed the recordset so it returned zero records and found once more that the hotkey worked once, and then stopped working.

OK I just found something.....

This is an Access 2007 database which uses SQL Server 2005 as a back end. Something that I do extensively is to use DSN-Less queries to provide a recordset for my forms. This approach has serverd me well for a number of years. So I wondered what will happen if I use a local table as the recordset. When I tried it, I found that the hotkeys worked perfectly every time.

So at the moment, it seems to be a quirk of using a DSN-less  query which is causing my problem.

hnasr: It is not practical to upload a sample because I only have the problem when my form is referencing a SQL Server database.
0
 
Jeffrey CoachmanMIS LiasonCommented:
<It is not practical to upload a sample because I only have the problem when my form is referencing a SQL Server database.>

You could run Make Table queries on the Linked SQL tables and make them local...
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Can you show the code behind that button?
0
 
TownTalkAuthor Commented:
@boaq2000: Yes I can run queries on the SQL data and make the tables local, but that's skirting around the problem instead of fixing it. If I cant find out what is causing this problem though, then that's what i'll probably do.

@lsmconsulting: I can show the code behind the button, but please remember that all of the buttons are experiencing this problem.

Private Sub NewItemButton_Click()
    Dim MyFilter As String
   
    Me![DummyField].SetFocus
    Me![NewItemButton].Enabled = False
   
    MyFilter = "Filter=OrderRef='" & Me![OrderNo] & "'"
   
    DoCmd.OpenForm "SalesOrderDetails", , , , , , MyFilter
    DoEvents
   
    Forms![SalesOrderDetails].NewRecordButton_Click
           
    Me.Visible = False
       
ProcExit:

    Me![NewItemButton].Enabled = True
   
Exit Sub

The first statement in that code moves the focus to a control called DummyField. When the problem occurs, that statement is not being executed and the focus stays on the button. In case anyone wonders why I am doing this, it's a standard thing I do now, in order to prevent problems caused by users double clicking command buttons. I always move the focus to a textbox of zero size and disable the button before commencing the task to be performed.

I was saying yesterday that I can get one instance of the hotkeys working immediately after visiting a Sales Order which contains details. I've found now that this isn't always the case. Sometimes when I come back to a Sales Order with no details, the hotkeys are not functioning at all. There are 11 enabled buttons on this form. The problem affects all of them.
0
 
Jeffrey CoachmanMIS LiasonCommented:
<Yes I can run queries on the SQL data and make the tables local, but that's skirting around the problem instead of fixing it. I>
No I meant running make table queries so that you could post the BD here...
0
 
Jeffrey CoachmanMIS LiasonCommented:
No I meant running make table queries so that you could post the BD here...
S/B
No I meant running make table queries so that you could post the DB here...
0
 
TownTalkAuthor Commented:
In one of the above posts I said that I found that this problem does not occur on a form which is bound to a local table. So I dont have a way to upload an example of the fault to you.

This problem only seems to occur when my form is bound to one of these DSN-less queries.

Even though you intended the maketable query just as a diagnostic tool. It does offer a permanent solution to this problem though.
0
 
TownTalkAuthor Commented:
There's been no further comment on this question for a few days now. So i'll accept the workaround suggested boaq. It's not a fix, but it will get my hotkeys working correctly again. Thanks everyone for your input.

Ian
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now