sendkeys alternative

sammers101

Registered User.
Local time
Yesterday, 19:29
Joined
May 11, 2012
Messages
89
So I have a binder with pages of cards, 3x3 on each page. I created a form with entries displayed also as 3x3 per page and command buttons for next and previous pages. I was using a report but switched to a form so I can update the inventory for the cards as I go from page to page. It's much easier to update this information when it is displayed the same way that they are physically kept.

So the form has a pagebreak in it, NO TABS, and a variable page length. Depending on which binder I select, the form could be 5 pages, could be 10.

The problem:
I am using sendkeys pgup and pgdn for the command buttons but I have read that this is a bad idea: access.mvps.org/access/api/api0046.htm
Sendkeys works fine if I opened the form directly, but when I open the form in a dialog window the next and previous buttons don't work. Maybe I need to do setfocus? But I figured finding an alternative to sendkeys altogether would be better.

Thanks in advance
 
You have not said what you expect send keys to do.
 
go to the next page for one button, previous page for the other button
 
go to the next page for one button, previous page for the other button

I am not an expert on send keys so I am stabbing in the dark a little.

Your reply is what I thought you may say. What is wrong with using the Pg Up and the Pg Dn buttons. Do they not do what you want.
 
Correct, it works when I open the form directly from the navigation pane. But when I open the form using a command button in a dialog window, clicking the buttons does nothing.
I'm using a command button Onclick
data mode: edit
window mode: Dialog
 
sammers101

I asked "What is wrong with using the Pg Up and the Pg Dn buttons. Do they not do what you want."

to which you replied "Correct"

Perhaps you did not understand the question.

Spike, thanks for jumping in.
 
Setfocus() is what initially sprang to mind, one suitably named control at the top, and possibly one at the bottom, of each page then set the focus using your next & previous buttons.

OR

A Tab control with each "page" being a separate tab holding a 3x3 grid of controls. Create enough tabs to cover what you might need and make them visible / invisible as required.

OR

A single 3 x 3 grid of controls and use an array, or recordset, to programatically update the labels and other values associated with the controls. Your previous and next buttons would then step through and change the controls accordingly giving you "virtual" pages.

What are you using to display the cards, Subforms?
 
Last edited:
@rainlover I was confused by what you said. Now that I'm typing this I realize you meant the physical pgdn button not the command button. I just tried it now and it doesn't work using the dialog window

@nanscombe I was thinking setfocus might work, I am not very familiar with vba so I wasn't sure.

Not sure how to do option two with a variable page length

option three sounds similar to what I'm doing now, I think. Perhaps if you explain in more detail

Currently I am using a continuous form with a pagebreak, maybe this isn't what I should be doing? I've uploaded a simplified version of my database if that helps.

Navigate to setup foil by pressing Binder foils at the top of the page. The prev and next buttons don't work, however when I open setup foil in the navigation pane they work just fine.
 

Attachments

Last edited:
After a quick play with it I came up with a crude fix, it's not too precise but it functions. I'll have another think later.

It works by using RecordsetClone, which is a virtual copy of the recordset. It moves the cursor forward or backwards by 2 records, and then moves the forms record to match.

Code:
Private Sub Command38_Click()
'SendKeys "{PgUp}"

  With Me.RecordsetClone
    If Not .BOF Then .Move -2
    If .BOF Then .MoveFirst
    Me.Bookmark = .Bookmark
  End With
End Sub

Private Sub Command57_Click()
'SendKeys "{PgDn}"

  With Me.RecordsetClone
    If Not .EOF Then .Move 2
    If .EOF Then .MoveLast
    Me.Bookmark = .Bookmark
  End With
End Sub
 
You have to remove your key trap macros to test the PgUp and Down. There is no reason why they wouldn't work directly. You should not have to use SendKeys to make them work.
 
I appreciate all the help guys.

@ nanscombe I tried your code, and I get this error.
Run-time error '3159':
Not a valid bookmark

@pat hartman I removed the send keys code and tried just using the keyboard buttons (would have been an acceptable temporary solution) but even those don't work in the dialog window :( They work just fine when I open directly from the navigation pane. I don't understand why

Note: The form does have 6 page breaks, I really only need one. Could that be causing the problem? As for why I have 6...I added one and it didn't seem to break the page so I added a couple more and suddenly it worked. I sound like an idiot..page breaks giving me such a headache
 
Any ideas? I feel like something weird is happening because everybody keeps offering solutions that SHOULD work but don't.
 
I would like to help however I run Access 2003 as do many other members.

If you could convert to A 2003 then I could have a proper look at your problem.

Could you also explain what you mean by the Dialogue Window. I assume this has something to do with your version of Access.
 

Users who are viewing this thread

Back
Top Bottom