goto 1st field of subform

I have a form with an add button.  When I click on the button I would like to go to the first field in the header of my subform.  I've tried the following and so far nothing works.
Please help!

This one takes me to the first field in the detail section.  I need the first field in the header
   DoCmd.GoToControl "fsubPlacementQues"

With these two I just get an error "no field named..."
DoCmd.GoToControl "Forms![fsubPlacementQues]![txtPlacementReviewDate]"
DoCmd.GoToControl "Forms![frmPlacementReview]![fsubPlacementQues]!Form![txtPlacementReviewDate]"
BobRosasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
try this

Me.fsubPlacementQues.Form.txtPlacementReviewDate.SetFocus
0
BobRosasAuthor Commented:
Thanks for your quick response!  Atleast I didn't get an error but it still takes me to the first record in the detail.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
ok ... what is the control name in the Header ?

mx
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

BobRosasAuthor Commented:
The name of the field that I want to move to is txtPlacementReviewDate
Is that what you are asking me?
But I think I found something else.  I posted some of my code below.  I write to 2 files and then in order to display what I wrote I close the form and re-open it.  Your code is probably ok.  I think it's my timing, and I'm just not sure how to fix it.  The code below takes me to the first field in the detail.  But when I tried moving your line of code after I reopen the form I get the message...The expression  you entered referes to an object that is closed or no longer exists.
Any thoughts!
Thanks so much!

Private Sub cmdAdd_Click()
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("dbo_tblPlacementReview", DB_OPEN_DYNASET, dbSeeChanges)
    Set rs1 = db.OpenRecordset("dbo_tblPlacementQues", DB_OPEN_DYNASET, dbSeeChanges)
        'code to add data to tblPlacementReview table
        'code to add to tblPlacementQues
    Me.fsubPlacementQues.Form.txtPlacementReviewDate.SetFocus
    rs.Close
    rs1.Close
    DoCmd.Close
    DoCmd.OpenForm "frmPlacementReview"
0
GRayLCommented:
Try:

Me!fsubPlacementQues.Form!txtPlacementReviewDate.SetFocus

if indeed txtPlacementReviewDate is the name of the control in the subform header.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
gRay ... that was my first post :-)

mx
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
bob - I missed something

try this - two lines are needed:

Me.fsubPlacementQues.SetFocus                ' focus to subform control first
Me.fsubPlacementQues.Form.txtPlacementReviewDate.SetFocus   ' then the actual control

mx
0
BobRosasAuthor Commented:
I think we're getting closer.  At least now when I click on the add button I can see the cursor appears to go to the field I want it to and then it goes right back to the first field in the detail.  It's really just a quick flash of the field but I think that's what it's doing.  Sorry to be such a problem.
0
GRayLCommented:
Not quite.  Check the implicit references.  Not that you need it, but this from A2003 Help (notice the upgrade!:))

Each Form object has a Controls collection, which contains all controls on the form. You can refer to a control on a form either by implicitly or explicitly referring to the Controls collection. Your code will be faster if you refer to the Controls collection implicitly. The following examples show two of the ways you might refer to a control named NewData on the form called OrderForm:

' Implicit reference.
Forms!OrderForm!NewData
            
' Explicit reference.
Forms!OrderForm.Controls!NewData
            
The next two examples show how you might refer to a control named NewData on a subform ctlSubForm contained in the form called OrderForm:

Forms!OrderForm.ctlSubForm.Form!Controls.NewData
            
Forms!OrderForm.ctlSubForm!NewData

0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
My post:
Me.fsubPlacementQues.Form.txtPlacementReviewDate.SetFocus

Your Post:
Me!fsubPlacementQues.Form!txtPlacementReviewDate.SetFocus

What am I missing ?

Kudos on the Upgrade !!
0
BobRosasAuthor Commented:
I tried both and I still can't get it to work.  Is there a work around or anything?
Thanks!
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Post the exact code you have now

thx.mx
0
BobRosasAuthor Commented:
Here you go.  I posted all the code I have in my add button.  
I think that since I set focus and then re-open the form that it reverts back.  But if I place the code after I reopen I get an error.  
Thanks so much!

Private Sub cmdAdd_Click()
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("dbo_tblPlacementReview", DB_OPEN_DYNASET, dbSeeChanges)
    Set rs1 = db.OpenRecordset("dbo_tblPlacementQues", DB_OPEN_DYNASET, dbSeeChanges)
        'add date to tblPlacementReview table
        With rs
            .AddNew
            !PlacementID = Forms![frmPlacement]![fsubPlacement].Form![txtPlacementID]
            !PlacementReviewDate = Date
            .Update
            'to get last PlacementReviewId available because it's used below
            .MoveLast
            [txtPlacementReviewNewID] = !PlacementReviewID
        End With

        'add all questions for that date to tblPlacementQues
        With rs1
            .AddNew
            !PlacementReviewID = [txtPlacementReviewNewID]
            !PlacementQuesLkUpID = 1
            .Update
            .AddNew
            !PlacementReviewID = [txtPlacementReviewNewID]
            !PlacementQuesLkUpID = 2
            .Update
            .AddNew
            !PlacementReviewID = [txtPlacementReviewNewID]
            !PlacementQuesLkUpID = 3
            .Update
        End With
    Me.fsubPlacementQues.SetFocus                ' focus to subform control first
    'Me.fsubPlacementQues.Form.txtPlacementReviewDate.SetFocus   ' then the actual control
    Me!fsubPlacementQues.Form!txtPlacementReviewDate.SetFocus
    rs.Close
    rs1.Close
    DoCmd.Close
    DoCmd.OpenForm "frmPlacementReview"
End Sub

0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
"But if I place the code after I reopen I get an error.  "

What is the error ?  And what line of code ?

mx

0
BobRosasAuthor Commented:
If use the following code I get this error as shown below
The expression  you entered referes to an object that is closed or no longer exists.

    rs.Close
    rs1.Close
    DoCmd.Close
    DoCmd.OpenForm "frmPlacementReview"  'opening this opens the subform so  don't get the err
    Me.fsubPlacementQues.SetFocus                ' ERROR HERE
    Me.fsubPlacementQues.Form.txtPlacementReviewDate.SetFocus
0
GRayLCommented:
Mx: Re My Post/YourPost

use of the exclamation mark (implicit) versus period(explicit), versus the 'use a period everywhere' version which the parser can accept in a lot of cases.  I still stand by the old saw - If I made it use ! - If Microsoft made it use .
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Ok ... what is the name of the form with the Header ?   frmPlacementReview  ??

Lets say it's called Form1 ... then


    Form1.fsubPlacementQues.SetFocus                
    Form1.fsubPlacementQues.Form.txtPlacementReviewDate.SetFocus

or

    frmPlacementReview.fsubPlacementQues.SetFocus                
    frmPlacementReview.fsubPlacementQues.Form.txtPlacementReviewDate.SetFocus
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
I use periods everywhere all the time ... for years - because Intellisense works.

This:

' Implicit reference.
Forms!OrderForm!NewData
           
' Explicit reference.
Forms!OrderForm.Controls!NewData

The difference here is the use of Controls, not the !

Could also be

Forms.OrderForm.Controls.NewData

Note the Help snippet does not refer to periods or bangs ...

This *would* fail:

Forms!OrderForm!Controls!NewData     ! after OrderForm - before Controls

mx

0
GRayLCommented:
I would have written it:

             
    Form1!fsubPlacementQues.Form!txtPlacementReviewDate.SetFocus

or
               
    frmPlacementReview!fsubPlacementQues.Form!txtPlacementReviewDate.SetFocus
0
GRayLCommented:
When ever I use periods referencing a field of a recordset I get an error:

rs!myFld = "abc"      this works
rs.myFld = "abc"      this didn't (at least in A2K)

I just noticed the last two lines of my Help excerpt is is error.  Going to test.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
rs!myFld = "abc"      this works
rs.myFld = "abc"      this didn't (at least in A2K)

Not the same thing.  This is one place where you need the !   to refer to a Field in a record set.  

rs![YourField] ... I have to use !'s here ... sorry I didn't mention that.

mx
0
BobRosasAuthor Commented:
I doubled points and awarded both of you.  I hope that's ok.  You both stuck by me and went above and beyond for what should have been an easy one.  Thanks so much.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
np ... glad it works !..!!.....!...!.!

mx
0
GRayLCommented:
Forms!OrderForm.ctlSubForm.Form!Controls.NewData
-------------------------------------------^--this should be a period            
Forms!OrderForm.ctlSubForm!NewData
---------------------^--this should be a bang

When I try to define a field of a recorset using a period as in updating a record, the period throws an error.  I have to use the bang.  
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
gRay ... see my post just above - before Open Discussion ...
0
GRayLCommented:
These posts are sure not arriving in my Inbox in what you would call a timely fashion.  Thanks for the dialog.  In my post at http:*a20845561 I was pointing out the error in the A2003 Help file - to think they've had 5 years to get it right!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.