Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Location
    Nashville, TN
    Posts
    557

    Unanswered: How to Goto New Record in Subform

    Goto new record in subform after opening form

    This is the code I have...
    Code:
    Option Compare Database
    
    Private Sub cmdEdit_Click()
        On Error GoTo cmdEdit_Err
        Expire = lstDate
        Expire = "#" & Expire & "#"
        DoCmd.OpenForm "Caulk"
        [Forms]![Caulk].RecordSource = "SELECT * FROM Caulk WHERE Caulk.Expires =" & Expire
        [Forms]![Caulk]![Caulk Change Subform].SetFocus
        DoCmd.GoToRecord(acDataForm, "Caulk Change Subform", acNewRec)
        
        
        
        DoCmd.Close acForm, "Select Caulk"
    cmdEdit_Exit:
        Exit Sub
    cmdEdit_Err:
        MsgBox Err.Description
        Resume cmdEdit_Exit
    End Sub
    Hope you can help,
    JS
    Have you ever thought about thinking on purpose?

    Jarvis Stubblefield
    Patriot Designs
    Web/Database Development and Consulting
    The-Patriot.net by Patriot Designs

  2. #2
    Join Date
    Feb 2004
    Posts
    137
    Try this modification to the code:
    Code:
    Private Sub cmdEdit_Click()
        On Error GoTo cmdEdit_Err
        Expire = lstDate
        Expire = "#" & Expire & "#"
        DoCmd.OpenForm "Caulk"
        [Forms]![Caulk].RecordSource = "SELECT * FROM Caulk WHERE Caulk.Expires =" & Expire
        [Forms]![Caulk]![Caulk Change Subform].SetFocus
    ' DoCmd.GoToRecord(acDataForm, "Caulk Change Subform", acNewRec)
    ' The above will not work because the subform is subclassed in the main form.
    ' Revise the statement to:
        DoCmd.GoToRecord , , acNewRec
        
        
        DoCmd.Close acForm, "Select Caulk"
    cmdEdit_Exit:
        Exit Sub
    cmdEdit_Err:
        MsgBox Err.Description
        Resume cmdEdit_Exit
    End Sub

  3. #3
    Join Date
    Mar 2004
    Location
    Nashville, TN
    Posts
    557
    Thanks a bunch worked like a charm. I just couldnt get it, but that was the complete logical choice :-P. I cant believe I didnt figure it out before you posted.

    Thanks again,
    Jarvis
    Have you ever thought about thinking on purpose?

    Jarvis Stubblefield
    Patriot Designs
    Web/Database Development and Consulting
    The-Patriot.net by Patriot Designs

Posting Permissions

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