0
votes

I have a public function on my main form that creates a new record in my subform (located on my mainform). I am trying to call the public function with a Yes/No message box. (Ie: Do you want to update the record? Yes - Creates a new record in the subform. No - Doesn't create a new record).

I am able to call the public function outside of the Y/N message box. However, once I put the code within the ElseIf statement, I receive an "You can't go to specified record." error on the "DoCmd.GoToRecord , , acNewRec" part of my public function.

Public Function NewEventEntry()
    'this public function creates an empty new record in the subform
    Me![subform_Events].SetFocus
    DoCmd.GoToRecord , , acNewRec
End Function


Private Sub RunUpdateQuery_Click()
    'calling the public function works fine here    
    'Call NewEventEntry

If DCount("*", "qry_CheckAllBadAddress") = 0 Then
MsgBox "All addresses are marked bad.", vbExclamation

ElseIf MsgBox("Do you want to update the addres?", vbYesNo + vbQuestion, "Warning") = vbYes Then

    'calling the public function here doesn't work; i receive an error saying: "You can't go to the specified record." the problem is in the public     function, specifically the DoCmd.GoToRecord , , acNewRec line
    Call NewEventEntry

End If
End Sub
1

1 Answers

0
votes
Me![subform_Events].SetFocus
DoCmd.GoToRecord , , acNewRec

How should VBA know, that you want to go to a new Record in the subform, not in the main form? ;-)

Try this:

DoCmd.GoToRecord , "subform_Events", acNewRec

I'm not sure if this works (long time since I used subforms). If not, I'd try something to do with DAO.recordset