Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    sjlevine34's Avatar
    sjlevine34 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    39

    Clearing Keyboard Buffer in Access VBA

    Is there a way to clear the keyboard buffer in access vba, something like the clear typeahead command in dbase?


    I have a situation where occasionally one of two clicks in a file dialog box is carrying over to the control (a textbox with a click subroutine that launches the file dialog box) resulting in the file dialog box being launched again. I would like to try clearing the keyboard buffer at the end of the click routine to see if it solves the problem.

    I am using a text box as a button control on a continuous form so it will display the value in the field as the label for the button. The fields are: Database Label (values "Database1" or "Database2"), Database path.

    The code of the click subroutine:


    Private Sub txtDatabaseSelectorTableID_Click()
    Dim lstrSelectedFile As String

    lstrSelectedFile = fSelectFile("InitPathDbase" & [TableID], "accdb")
    'Debug.Print lstrSelectedFile
    If lstrSelectedFile = "No File Selected" Then
    GoTo ExitDatabaseSelectorTableID_Click
    ElseIf lstrSelectedFile = "ERROR" Then
    MsgBox "File Selection Unsuccessful"
    GoTo ExitDatabaseSelectorTableID_Click
    End If
    Me.txtDatabase.Value = lstrSelectedFile
    Me.chkValid = fQuestionnairesMasterExists(lstrSelectedFile)
    If Me.Dirty Then
    Me.Dirty = False
    End If
    If Me.chkValid Then
    Me.btnLoadTempTable.Enabled = True
    Else
    Me.btnLoadTempTable.Enabled = False
    End If
    sDeleteAllRecords "ttblQuestionnairesMasterTemp" ' Delete all records from temporary table as they no longer represent
    ' databases in tblQMLTablesToCompare table .
    Me.btnViewEDC.Enabled = False
    Me.Refresh
    Me.txtDatabase.SetFocus ' set focus off of select buttons for visual display reasons

    ExitDatabaseSelectorTableID_Click:
    Exit Sub

    End Sub

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    I think simplest solution for me would be to change the single click event to double click.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    As always, in these cases, you need to step through the code and see why the input dialog is being called twice - if you have not done so. It could be due to the function you're calling (but don't show) or something like the saving of the form runs Current event code and that causes the second call. Watching the progression of your code will show you the chain of actions and allow you to check variable values as you go. I don't think clearing a buffer will solve the issue.

    P.S. please enclose code in code tags for easier reading (# on forum toolbar).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    sjlevine34's Avatar
    sjlevine34 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    39
    Thanks, davegri, Micron. I have thought about setting the click trigger to double click, and just might do that. Micron, I followed your advice and tried to step through the code using debugger, but I cannot seem to reproduce it. Furthermore, it only seems to affect the textbox on the first record, and only intermittently. So that is against a coding error. I thought about the keyboard buffer because I have a parkinsonian tremor in my right hand, which can and has resulted in extra clicks.

    Since the application is for my use only. I am going to let it go for now. Perhaps the best way to go in the future is to use a button control and a display only textbox in place of this attempt at a combination control. Again. Much thanks.

  5. #5
    sjlevine34's Avatar
    sjlevine34 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    39
    Problem goes away if I remove the click routine from the text box and overlay it with a transparent command control. It looks nicer, too.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If you're clicking fast enough, it would be interpreted as a double click. If you are not, then only one click would be causing anything to happen and when that code runs, the second click would be ignored. So to me, the click thing would be a red herring. If it's intermittent, that can be hard to fix. If it doesn't happen when you step through but regularly does when you don't step through, then it may be a timing thing - code is continuing before something needs to happen. If you want anyone to check it out, post a zipped db copy. Those functions you're calling can't be seen by us but might be relevant.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    sjlevine34's Avatar
    sjlevine34 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    39
    I am thinking it had something to do with the control being the first text box in the detail section. After one activation of the file dialog routine, the problem would rear its ugly head on that control and that control only. Timing was probably involved, though contributing may have been a non-kosher use of the textbox control. Replacing the text box with a real command control seems to solve the problem. Also, have just discovered that, by using the detail.Paint event, I can populate the caption of the command control specifically with the field value of that record specifically, thus doing away with the textbox entirely! This is the first time I have ever used the Detail.Paint event and it appears to be a nice feature.

    Thanks for your offer to review my code. I may need to take you up on it at a future time, but I am good for now.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If such controls are outside of the detail section (e.g. header), it might be worth noting that Me.Repaint would take care of all such changes on the entire form.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    sjlevine34's Avatar
    sjlevine34 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    39

    Able to reproduce in test database

    I have created a test database that recreates the problem. I have played with it and my findings are as follows.
    1. The relaunch of the file dialog box occurs only when I use a clickable text box AND, at the end of the sub, set the focus to the adjacent text box.
    2. I was wrong about it only affecting the clickable text box in the first record. It affects the clickable text box in all records.
    3. It only occurs if you click on a file in the file dialog box that is situated over the underlying clickable text box.

    I have attached a zip file containing this test database. To reproduce the problem, you will need a folder with at least10 files to select.
    Attached Files Attached Files

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I see no difference or abnormal result regardless of which form I use.
    EDIT - I use single click option, so maybe that matters?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    sjlevine34's Avatar
    sjlevine34 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    39
    You have to double click on the file in the file dialog window. That is an alternative to clicking on the file and then clicking ok. Furthermore, you have to repeat the steps on the same clickable text box several times to get the error.

    I should note that this is not the first time I have been flummoxed by a user-behavior issue. Years ago, I could not understand why data was changing in a table until I used the program myself and found that, in looking up records in the form involved. the first click of a double click turned focus on a combobox I had used to allow the user to select previously-used field content as a convenience in place of retyping it. The second click was selecting the first choice in the dropdown. Needless to say, by that time, the usefulness of the combobox had become very limited, so I replaced it with a simple text box, solving the problem. It goes to show that, sometimes, the bug is not in the code, but in the user. In that regard, I am sometimes my own worst enemy.

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I have never double clicked on a file dialog item; have always used the dialog buttons. I guess I mis-read post 7, which made it seem like the click problem was on clicking a textbox but I see that your original post indicates otherwise. I altered my single click setting and cannot reproduce the issue with double clicks on the chosen file icon in the file dialog with any of the forms. If your posted db isn't a virtual copy of your actual one, then that could be an issue. You may have left something out in your posted version that is causing it. If that is the case, I can't see how I can help further unless you can post a copy of the actual db.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    sjlevine34's Avatar
    sjlevine34 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    39
    Micron

    First, I want you to know that I really appreciate you for the time you have spent with me on this.

    I went ahead and downloaded the file from the website onto another laptop and was able to reproduce with the frmClickableTextBoxSetFocus form. The file you select has to be over the text box "Select File 1".

    In playing with this database, I am finding that the command button alone does not ensure that the text in the button always reflects the text for the underlying field in the record. Thus the transparent command button control overlying the disabled locked text box seems to be the best option. Shame they don't have a command control with a field source property.

    Again, thanks.

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I DID IT! Will think about it after java.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You probably know that you cannot alter just one button caption in a continuous form, hence your use of a bound textbox. There doesn't seem to be a way to disable double click on a file dialog but if there was, you'd be playing with user preferences and I'd advise against that. I thought about a module level variable to detect an initial click, thereby disallowing the second one, but that would never work because as soon as the event ends, it fires again, so you would have already reset the variable to its initial state. I also briefly thought about disallowing the second click based on whether or not there was already a path value, but this would prevent editing current values.

    So what I would do is make a small button on the left and have your caption textbox beside it, and use the button for the event and not the textbox.
    Click image for larger version. 

Name:	DblClick.jpg 
Views:	16 
Size:	6.0 KB 
ID:	43074
    Sometimes people overlay a textbox on a button but I find that while you can place one behind the other and make the upper one transparent, the background of the one that receives the focus seems to take precedence, then you have odd looking behaviours.

    This assumes that you need the textbox at all, since I'm not sure I see the point in enumerating the records like that. Does it matter if they show like that? Perhaps more importantly, you are relying on table order, which you cannot for 100% of the time. The records are like a bucket of marbles that have conveniently been extracted and displayed by the table in what you think is a logical order. If they get swapped around during some disk write, they won't appear in that order anyway - unless maybe you can and do impose a table level sort order. That is another reason why I virtually always have autonumber PK fields in tables and base my forms on queries with a pk sort order and not base them on tables. Your table doesn't have one.

    If in your real db you have spaces between names, suggest you avoid that (along with special characters).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. usu screen keyboard in access
    By Cuasitos in forum Programming
    Replies: 3
    Last Post: 05-13-2018, 10:30 PM
  2. Assigning Keyboard Shortcuts in Access
    By megan1989 in forum Access
    Replies: 1
    Last Post: 12-13-2014, 01:37 PM
  3. Access Form Requery (F5 on keyboard or reopening) handler?
    By superfury in forum Code Repository
    Replies: 0
    Last Post: 08-23-2013, 03:17 AM
  4. Replies: 4
    Last Post: 06-18-2013, 08:50 PM
  5. Replies: 1
    Last Post: 11-09-2012, 01:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums