Solved Error 3467 object is closed

ClaraBarton

Registered User.
Local time
Yesterday, 18:13
Joined
Oct 14, 2019
Messages
578
Code:
Private Sub btnClose_Click()
10    On Error GoTo btnClose_Click_Error
      Dim frm1 As Access.Form

20    DoCmd.Close _
            objectType:=acForm, _
            ObjectName:=Me.name
       
30     Select Case CallingForm
            Case Is = "frmCalendarAppt"
40            Set frm1 = Forms("frmCalendarAppt")
50            frm1!txtRecipe.Value = Me.txtRecipe.Value
60            frm1!txtNotes.Value = Me.txtPrepNotes.Value
70           Exit Sub
         
80        Case Is = ""
90           DoCmd.OpenForm "frmMenu"
100         Exit Sub

110       Case Else
              Dim frm As Form
120                   For Each frm In Application.Forms
130                       If frm.name = CallingForm Then
140                            frm.Visible = True
150                    Exit For
160                       End If
170                   Next frm
         
180   End Select

190   On Error GoTo 0
200   Exit Sub

btnClose_Click_Error:
210       MsgBox "Error " & Err.Number & " (" & Err.description & ") " & _
        " in procedure btnClose_Click, line " & Erl & "."

End Sub
I have a form that calls a second form to edit an entry. The calling form is frmCalendarAppt and is still open. Everytime I run this, however, I get Error 2467.
I've tried Forms!frmCalendarAppt. and every other way I can imagine. How do I carry the edited fields back to the calling form?
 
In which line does the error occur? Possibly in line 50?

Code:
20    DoCmd.Close _
            objectType:=acForm, _
            ObjectName:=Me.name  ' <----

       
30     Select Case CallingForm
            Case Is = "frmCalendarAppt"
40            Set frm1 = Forms("frmCalendarAppt")
50            frm1!txtRecipe.Value = Me.txtRecipe.Value   ' <-----

How about this:
Code:
Private Sub btnClose_Click()
10    On Error GoTo btnClose_Click_Error
      Dim frm1 As Access.Form

20    me.visible = false
       
30     Select Case CallingForm
            Case Is = "frmCalendarAppt"
40            Set frm1 = Forms("frmCalendarAppt")
50            frm1!txtRecipe.Value = Me.txtRecipe.Value
60            frm1!txtNotes.Value = Me.txtPrepNotes.Value
70          '  Exit Sub
         
80        Case Is = ""
90           DoCmd.OpenForm "frmMenu"
100         ' Exit Sub

110       Case Else
              Dim frm As Form
120                   For Each frm In Application.Forms
130                       If frm.name = CallingForm Then
140                            frm.Visible = True
150                    Exit For
160                       End If
170                   Next frm
         
180   End Select

190   DoCmd.Close _
            objectType:=acForm, _
            ObjectName:=Me.name

200   Exit Sub

btnClose_Click_Error:
210       MsgBox "Error " & Err.Number & " (" & Err.description & ") " & _
        " in procedure btnClose_Click, line " & Erl & "."

End Sub
 
Oh Wait!! Are you saying I closed the called form and that's where the problem is? Should that be after the case?
 
Once again I thought Access messed up. Turns out it was me! Imagine that!
 
By putting the close form at the end, the first form.visible doesn't work on the third case. Is there some way I can get all three cases to work?
 
Can you explain that another way? Didn't quite click.
 
By putting the close form at the end, the first form.visible doesn't work on the third case. Is there some way I can get all three cases to work?
You could put a debug.print frm.name inside that third case (inside the if block). Then see what forms are seen in the immediate window. Just checking if the code is even getting to that third case. If not, you need to change the order of the case statements or use different logic. No idea how your application is supposed to work.
 
How do I carry the edited fields back to the calling form?
If I'm reading your code correctly, your opening a form and then trying to pass data from that newly opened form back to the original form.

Rather than executing code in the newly opened form, execute it from within the calling form. No need to put any code at all in the edit form.

it would look something like:

Code:
Option Compare Database
Option Explicit

Dim WithEvents MyForm As Form

Private Sub Command0_Click()

    DoCmd.OpenForm "Form2"

    Set MyForm = Forms("Form2")

    MyForm.OnClose = "[Event Procedure]"

End Sub

Private Sub MyForm_Close()

    Me.Tbx1 = MyForm.Tbx1
    Me.Tbx2 = MyForm.Tbx2

    Set MyForm = Nothing

End Sub
 

Attachments

"Object is closed."
Thank you Doc, but I was trying to get the O/P to realise that they have to supply a little more info, not expect us to go looking for it all the time. :(

Some seem to think that someone knows all the error messages off by heart? :)
 
btw, Using a form variable with WithEvents also allows you to pass data from the calling form to newly opened form, as well as retrieving info from it.

Code:
Private Sub Command0_Click()

    DoCmd.OpenForm "Form2"

    Set MyForm = Forms("Form2")

    MyForm.OnClose = "[Event Procedure]"

    MyForm.SomeField = "XYZ"

End Sub
 
Moke123... Error 2450 cannot find the referenced form...
Code:
Option Compare Database
Option Explicit
Dim WithEvents frmEditRecipe As Form

Private Sub btnEditRecipe_Click()
Dim strWhere As String
strWhere = "RecipeID =" & Me.txtRecipeIDFK

    DoCmd.OpenForm "frmAddEdit", _
        WindowMode:=acDialog, _
        WhereCondition:=strWhere, _
        OpenArgs:=Me.name

Set frmEditRecipe = Forms("frmAddEdit")
frmEditRecipe.OnClose = "[Event Procedure]"
       
End Sub
If I understand this right, this code runs after frm2 (frmAddEdit) has closed:
Code:
Private Sub btnClose_Click()
10    On Error GoTo btnClose_Click_Error

20        DoCmd.Close _
            objectType:=acForm, _
            ObjectName:=Me.name
         
30        If IsNull("CallingForm") Then
40           DoCmd.OpenForm "frmMenu"
50          Exit Sub

60        Else
              Dim frm As Form
70                    For Each frm In Application.Forms
80                        If frm.name = CallingForm Then
90                             frm.Visible = True
100                    Exit For
110                       End If
120                   Next frm
130     End If
 
Have a look at line 30 in the code you posted.

The string literal will never be Null.

Is CallingForm a variable?

If so, where is it declared?
 
Yes. It's on every form at the top. Form variable? it works anyway.
My problem is getting the variable frmEditRecipe filled with the closing form frmAddEdit. It works on Moke123's example but can't find it on mine. It is not clear to me why it would find it when I think the form is closing before the variable is filled.
Oops... I forgot to include the sub that follows:
Code:
Private Sub frmEditRecipe_Close()
    Me.txtRecipe = frmEditRecipe.txtRecipe
    Me.txtNotes = frmEditRecipe.txtPrepNotes

Set frmEditRecipe = Nothing
 
End Sub
I am trying to pass 2 field values back to the calling form.
 
How is it declared? As a String? As Acces.Form?

Ignore that - I see it must be as String (or As Variant)
Code:
' ...
80                        If frm.name = CallingForm Then
' ...
 
Last edited:

Users who are viewing this thread

Back
Top Bottom