Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PgDown from subform to move to next rec on main form

Status
Not open for further replies.

lgbatdw

Programmer
Aug 11, 2004
44
US
I would like to use PgUp and PgDown on a subform and have it move to the previous (pgup) or next(pgdown) record on the main form. I think I need to set the KeyPreview on the subform to Yes and set code on the subform on keydown event based on keycodes, but I keep running into an error on the GoToRecord command which says "The object 'frmMasterPatientVisit' isnt open." Any help on this would be helpful. It's probably something simple that I am just not getting. Here is my code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim ctl As Control

Select Case KeyCode
Case vbKeyPageUp
' Process PageUp key events.
Set ctl = Forms!frmMasterTimeEntry!frmMasterPatientVisit
DoCmd.GoToControl ctl.Name
DoCmd.GoToRecord acDataForm, ctl.Name, acPrevious
Case vbKeyPageDown
' Process PageDown key events.
Case Else
End Select
End Sub

Linda in MN
 
It appears that you're trying to set the focus to your subform control on the main form. I think you really need to set the focus to some other control on the main form instead. When you set the focus to a subform control, the subform itself steals the focus for its active control, so that isn't getting you anywhere.

BTW, instead of "DoCmd.GoToControl ctl.Name" I would use "ctl.SetFocus". That may just be a matter of personal preference, though.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Thanks RickSpr. I didn't mention that I was actually working with 3 forms: a main form and a subform that contained another subform. I wanted to move from the 2nd subform to the 1st subform. Anyhow - it's working with your help. Thanks again!

Linda in MN
 
How are ya rick . . . . .

I couldn't agree with you more about [blue]SetFocus[/blue] vs [blue]DoCmd[/blue]. In fact I've learned never to use DoCmd unless there's no other way. [blue]There are enough circumstances where DoCmd will fail[/blue] . . . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top