moke123
AWF VIP
- Local time
- Yesterday, 21:18
- Joined
- Jan 11, 2013
- Messages
- 4,396
the 2450 error is because you are opening the form in dialog mode. This pauses the code in the calling form so the form variable is not set. In your edit form go to the properties and set the form to modal and remove the WindowMode:=acDialog in your docmd.openform arguments.. This will have the same effect as dialog without pausing the code in the calling form.
This code should be in the calling form, not the edit form.
What this is is a custom event for the edit form but it is contained in the calling form.
When the edit form is closed the Private Sub MyForm_Close() is run (from the calling form). You do not have to put any code in the edit form for this to work.
Set MyForm = Forms("frmAddEdit") sets a reference to the edit form.
This allows you to do a few things with the edit form from the calling form.
for instance if you wanted to set the form caption you can simply write MyForm.Caption = "My Edit form" after the set statement.
Or set a field value on the edit form with MyForm.SomeField = "Xyz"
Private Sub MyForm_Close() is a custom event that "listens" for the MyForm variable to close and then handles the event if and when it happens. This is all from the calling form.
This code should be in the calling form, not the edit form.
What this is is a custom event for the edit form but it is contained in the calling form.
When the edit form is closed the Private Sub MyForm_Close() is run (from the calling form). You do not have to put any code in the edit form for this to work.
Set MyForm = Forms("frmAddEdit") sets a reference to the edit form.
This allows you to do a few things with the edit form from the calling form.
for instance if you wanted to set the form caption you can simply write MyForm.Caption = "My Edit form" after the set statement.
Or set a field value on the edit form with MyForm.SomeField = "Xyz"
Private Sub MyForm_Close() is a custom event that "listens" for the MyForm variable to close and then handles the event if and when it happens. This is all from the calling form.
Code:
Option Compare Database
Option Explicit
Dim WithEvents MyForm As Form ' a form variable
Private Sub btnEditRecipe_Click()
Dim strWhere As String
strWhere = "RecipeID =" & Me.txtRecipeIDFK
DoCmd.OpenForm "frmAddEdit", _
WhereCondition:=strWhere
Set MyForm = Forms("frmAddEdit") 'set the form variable
MyForm.OnClose = "[Event Procedure]" 'make sure that the form variable has event procedure in the close event.
End Sub
Code:
Private Sub MyForm_Close()
Me.txtRecipe = MyForm.txtRecipe
Me.txtNotes = MyForm.txtPrepNotes
Set MyForm = Nothing
End Sub