Tabbing from one subform to another

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have created a main page that has a series of subforms. A user will pull
up the main form and enter date into the first subform. The info would be
things such as WeeklyProdRevenue and WeeklySerRevenue. When they type in
this data it fills into a table called WeeklyRevenue with these two fields.
I then want the user to press tab and have the cursor jump to the next sub
form called Monthly Revenue which basically has two similar fields
(MonthlyProdRevenue and MonthlyServRevenue) that go into a table called
MonthlyRevenue. Instead, when the user presses tab after typing in a value
for WeeklySerRevenue it takes the user to a blank second record of the
WeeklyRevenue table which I don't want rather than jumping to the next sub
form. I took away the record selectors because I only want one record per
table in this application. After everything is typed in I run a delete query
to empty single record of all tables. Can someone help?

Thanks,
 
Set the each subform's KeyPreview property to Yes. Then in each subform, use
the KeyDown event to move the cursor. For example, in the WeeklyRevenue
form's KeyDown event, put:

If KeyCode= 9 Then
Me.Parent.sfrmMonthlyRevenue.SetFocus
End If

This will move focus to the first control in the MonthlyRevenue subform.

HTH,
Barry
 
Barry,

Thanks for your help. I went ahead and followed your directions setting
each subforms KeyPreview property to Yes. I then went to the On Keydown,
click on the button with the three dots and select code builder. I then
entered the following code. The first and last line were already there so I
enter the code you suggested into the middle. LFCMonthlyRevenue is the name
of the subform. Whenever I tab, it still does not jump from one subform to
another, it simply takes me to the second record of the table which of course
is blank. Any idea as to what I am doing wrong?

Thanks,

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
Me.Parent.LFCMonthlyRevenue.SetFocus
End If

End Sub
 
You need to make sure you're referring to the Subform control, not the source
form. When you put a subform on a form, it's housed in a form control. This
control can have a different name from the form it contains. The code you
used must refer to the subform control, not the subform's form (starting to
sound like an Abbot and Costello routine). For this reason and to maintain
clarity, I usually change the name of the subform control to "sfrm" and then
the name of the source form. In your case, you could change the name of the
subform control to sfrmLFCMonthlyRevenue.

Does this make sense?

Barry
 
Barry,

I went ahead and renamed all of my subforms by adding sfrm in from of their
names. The main form is called EnterData. I then went to the code builder
section of sfrmLFCMonthlyRevenue and went to the event procedure of On Key
down and went to the code and added sfrm in front of the old subform name.
Now whenever I press the tab key I get a debugger message even if I am within
that subform trying to tab from one field to another.

Any thoughts on these errors?

Thanks,

Chuck
-------------------------------------------------------------------------------
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
Me.Parent.sfrmLFCMonthlyRevenue.SetFocus
End If

End Sub
 
What message are you getting?

ChuckW said:
Barry,

I went ahead and renamed all of my subforms by adding sfrm in from of their
names. The main form is called EnterData. I then went to the code builder
section of sfrmLFCMonthlyRevenue and went to the event procedure of On Key
down and went to the code and added sfrm in front of the old subform name.
Now whenever I press the tab key I get a debugger message even if I am within
that subform trying to tab from one field to another.

Any thoughts on these errors?

Thanks,

Chuck
-------------------------------------------------------------------------------
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
Me.Parent.sfrmLFCMonthlyRevenue.SetFocus
End If

End Sub
 
It is a Microsoft Visual Basic Error. It then says Run Time error 2452. The
expression you entered has an invalid reference to the Parent Property.

When I click on Debug it highlights the line:

me.parent.sfrmLFCMonthlyRevenue.SetFocus
 
This code should be in the KeyDown event of the subform. The Parent property
is a reference to the form that contains the subform. sfrmLFCMonthlyRevenue
is a reference to another control on the containing (parent) form. Is your
code in the correct place? Is everything spelled correctly?

Barry
 
Barry,

I checked the on Key Down of the main form which is called Enter Data.
There is no code here. I opened each subform as a separate form and there is
code there in the on Key Down section. In this code is the name of each
subform. Do you think I can give you a quick phone call to go over what I
have?

Thanks,
 
I'd prefer not to post my phone number. Drop me an email at barry dot gilbert
at hunterdouglas dot com.

Barry
 
Back
Top