View Single Post
  #8  
Old July 17th, 2004, 01:39 AM
Brandon
external usenet poster
 
Posts: n/a
Default How can I move the focus to a control on a subform?


-----Original Message-----
"Brandon" wrote in message

Ok, the only thing that doesn't work properly is the

goto
record command. I made the changes you suggested, but

the
goto record command actually takes me to a new record on
the third level form (sfrmLotBreakout) even though I

have
set the focus to the fourth level form and it does

indeed
have the focus. I only want to go to a new record on

the
fourth level form because the forms are linked and

records
are prepopulated with the linked info. If I go to a new
record on the third form, I lose my division and

location
information I have entered.
Here is the code

Dim curSavingsByMonth As Currency
Dim intMonth As Integer
'Dim rstTable As Recordset
'Dim dbsScorecard As Database
Dim x As Integer
Dim intContractLength As Integer
Dim intContractStart As Integer
Dim curSavingsAmt As Currency
Dim curHistoric As Currency
Dim curAward As Currency

'Set dbsScorecard = OpenDatabase("E-Scorecard.mdb")

'Set rstTable = _
' dbsScorecard.OpenRecordset("tblLotAwardBreakout",
dbOpenDynaset)
intContractLength = Me!ContractLength.Value
intContractStart = Me!ContractStart.Value
x = 1
intMonth = intContractStart
curHistoric = Me!HistoricVolume.Value
curAward = Me!AwardBidAmt.Value
curSavingsAmt = curHistoric - curAward
curSavingsByMonth = curSavingsAmt / intContractLength

Me!sfrmLotAwardBreakout.SetFocus

For x = 1 To [ContractLength].Value
'calculate the monthly savings and add records
'to the subform Brandon Cheal 7/14/04
DoCmd.GoToRecord , , acNewRec
Me!sfrmLotAwardBreakout!SavingsMonth.Value =
_intMonth
Me!sfrmLotAwardBreakout!Savings.Value =
_curSavingsByMonth
intMonth = intMonth + 1
Next x


End Sub


Hmm, that surprises me, but now that I test it, I get the

same results.
I *think* it's a bug, but maybe someone will pop up and

tell me I'm just
wrong about how GoToRecord is supposed to work.

Anyway, the immediate question is how to work around it.

My inclination
in cases like this -- and I've been suppressing it all

along -- is to
forget about form operations and just add the records

directly to the
table, and then requery the form if necessary. So your

code might be
modified like this:

With Me!sfrmLotAwardBreakout.Form.RecordsetClone
For x = 1 To intContractLength
'calculate the monthly savings and add records
'to the subform Brandon Cheal 7/14/04
.AddNew
!SavingsMonth = intMonth
!Savings = curSavingsByMonth
.Update
intMonth = intMonth + 1
Next x
End With

You may or may not have to requery the subform when

you're done:

Me!sfrmLotAwardBreakout.Requery

Since you're working on the subform's recordsetclone, I'd

try it first
without requerying, and only add the requery if it's

necessary.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.

Dirk, no need to requery and it works like a charm!!!! I
can't tell you how excited I am! Have a great weekend and
thanks again for all your help!

Brandon