Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Delta, Br. Columbia
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Record positioning (2000/XP)

    I have some code in a main/sub form that adds a new record to the underlying query for the main form if requested by the user. What I have been unable to do is after the Requery process to display this new record in the form. Bookmarks don't work as they get reset with a Requery. I have tried using a Find but the D/B will not let me set the focus to the control on the main form. The code I am using is as follows:

    tmpID = Me.PR_ID
    Set tmpRST = CurrentDb.OpenRecordset("tblPropagation")

    With tmpRST
    .AddNew
    ![PR_Cutnum] = Forms!frmProp_FillPropHouse!WCutNum
    ![PR_GenusID] = Me![PR_GenusID]
    ![PR_PlantID] = Me![PR_PlantID]
    ![PR_Size] = Me![PR_Size]
    ![PR_Date_Added] = Me![PR_Date_Added]
    ![PR_Hormone] = Me![PR_Hormone]
    ![PR_Wound] = Me![PR_Wound]
    .Update
    End With
    Me.Requery
    Forms!frmProp_Cutn_Enter.SetFocus
    Forms!frmProp_Cutn_Enter!PR_ID.SetFocus ***This fails with a cannot set focus to this control error *****
    DoCmd.FindRecord tmpID, acAnywhere, True, acSearchAll, True, acCurrent, True
    Me.Refresh

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Record positioning (2000/XP)

    Are you adding a new record to the main form or the subform? Is the subform continuous or single record?

    Does the new record actually get created? ie if you go and look in the atable is the record there? Is it correct?

    If you close the form and reopen it, can you get the record to appear?
    Regards
    John



  3. #3
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Delta, Br. Columbia
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Record positioning (2000/XP)

    I am adding a new record to the Main form and the sub form is continuous. I am not adding any records to the sub form.

    Yes the new record is created perfectly correctly and shows in the form after the Requery (I do not have to close and reopen). Then moving through the records I can find it. (The Requery action repositions the recordset at the beginning again)

    What I want to be able to do is: after it is created and after the Requery action go to the new record or even the one before on which the new one is based.

    .

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Record positioning (2000/XP)

    So the problem just seems to be the Setfocus line.

    Can you normally set the focus to this field? Can you click your mouse in this field? Has its enabled property been set to "No".

    Anmother approach to this whole task would be just to store the values for the new record in code, then use to the command

    DoCmd.GoToRecord , , acNewRec

    then set values in the new record directly into the form from the values held in variables.

    You won't hjave to find the new record - it will be on the screen.
    Regards
    John



  5. #5
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Delta, Br. Columbia
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Record positioning (2000/XP)

    Your "another approach" makes the most sense I will try it out. Many thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •