View Single Post
  #1  
Old July 15th, 2004, 04:37 PM
Brandon
external usenet poster
 
Posts: n/a
Default How can I move the focus to a control on a subform?

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.sfrmL otAwardBr
eakout.savingsmonth.SetFocus
'why won't the previous line set the focus?
DoCmd.GoToRecord
acDataForm, "sfrmlotawardbreakout", acNewRec
[SavingsMonth].Value = intMonth
frmprojectentry.sfrmlotentry.sfrmlotbreakout.sfrmL otAwardBr
eakout.savings.SetFocus
[Savings].Value = curSavingsByMonth
intMonth = intMonth + 1
Next x


End Sub