View Single Post
  #2  
Old July 16th, 2004, 04:08 AM
Byron
external usenet poster
 
Posts: n/a
Default How can I move the focus to a control on a subform?

To move the focus to a control on the subform you will
need to use somethin like:
Forms!MainFormName!FirstSubFormName!SecondSubFormN ame!
ThirdSubFormName.ControlName.SetFocus

You can set the value you want in the control using the
same type of statement, like:
Forms!MainFormName!FirstSubFormName!SecondSubFormN ame!
ThirdSubFormName.ControlName = Some
value

You can get both at the same time using a With statement"
With Forms!MainFormName!FirstSubFormName! _
SecondSubFormName!ThirdSubFormName.ControlName
.value = somevalue
.setfocus
End With

HTH

Byron
-----Original Message-----
Hi.
I have a form with project information. I have three
subforms all nested within the higher level form for a
total of 4 levels within this form. On the third level
(the second level of subforms), I enter total savings

per
project, number of months the savings will take place
over, and a start month. The fourh level (third nested
subform and the final level) is linked by Project

Number,
Phase Number, Division, and Location, so those fields

are
automatically filled for each new record. What i want

to
do in code is take the savings amt divided by the number
of months and enter in that amt for each of the months.

I have a time period table with an integer ID for each
month and they are in numerical order.
So I just need to set the focus to the fourth level

(third
level subform) and create the records by filling in the
savings month and savings amt. So I am using a Next

loop
along with the goto record command (using new record as
the argument).

Give me some tips on how to get the code to work. I

can't
even set the focus to the controls with this code. TIA

Private Sub cmdCalcMonthlySavings_Click()

Dim curSavingsByMonth As Currency
Dim intMonth As Integer
Dim x As Integer


x = 1
intMonth = [ContractStart].Value
curSavingsByMonth = [AwardBidAmt].Value /
[ContractLength].Value

For x = 1 To [ContractLength].Value
'calculate the monthly savings and add records
'to the subform Brandon Cheal 7/14/04

frmprojectentry.sfrmlotentry.sfrmlotbreakout.sfrm LotAward

Br
eakout.savingsmonth.SetFocus
'why won't the previous line set the focus?
DoCmd.GoToRecord
acDataForm, "sfrmlotawardbreakout", acNewRec
[SavingsMonth].Value = intMonth
frmprojectentry.sfrmlotentry.sfrmlotbreakout.sfrm LotAward

Br
eakout.savings.SetFocus
[Savings].Value = curSavingsByMonth
intMonth = intMonth + 1
Next x


End Sub
.