Form not recognized but it is already open (1 Viewer)

Zydeceltico

Registered User.
Local time
Today, 01:18
Joined
Dec 5, 2017
Messages
843
Form1 has a command button that opens Form2.

Form2 has two buttons on it,
I want one of the buttons to be invisible when Form2 opens.

Here's the code:
DoCmd.OpenForm "frmLineStop", acNormal, , , acFormEdit, acDialog, Me.txtInspectionEvent_PK
Forms![frmLineStop].[cmdAddtlNotes].Visible = False


It doesn't work. ......in a weird way.............Form2 opens, both buttons are visible, I enter a bunch of data, then I click to save and when Form2 closes I get error 2450: Access cannot find the referenced form 'frmLineStop.' I click Debug and it takes me to the code I've pasted above with the second line of code highighted yellow.

It's like it has waited until the form closes to run the second line of the OpenForm code - - or something.

Anyway.........I use this same exact code on a different form but the exact same setup and procedure and it works fine. I;ve checked spelling, copied and pasted. Making me nuts.

What are you able to see that I cannot?

Thanks!

Tim
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 01:18
Joined
May 21, 2018
Messages
8,525
It's like it has waited until the form closes to run the second line of the OpenForm code - - or something.
Yes that is expected. If you open a form ACDIALOG code execution stops in the calling code until the called form is closed.
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:18
Joined
Sep 21, 2011
Messages
14,231
So why not make it invisible to start with, then make it visible when required.?
 

Zydeceltico

Registered User.
Local time
Today, 01:18
Joined
Dec 5, 2017
Messages
843
So why not make it invisible to start with, then make it visible when required.?
Because I reopen Form2 later and want the visibility of the two buttons reversed. I'll see what happens.
 

Zydeceltico

Registered User.
Local time
Today, 01:18
Joined
Dec 5, 2017
Messages
843
So why not make it invisible to start with, then make it visible when required.?
I figured it out. I forgot I had the following on the Load Event Form2. I added the correct lines to the opposite halves of the If...Else..........and it works. I'm tired. :) Time to stop.

Code:
Private Sub Form_Load()
    Dim ctl As Control
    
  Dim rs As DAO.Recordset
    If Not Trim(Me.OpenArgs & " ") = "" Then
        'See if record exists
        Set rs = Me.Recordset
        'MsgBox "This is the InspectionEvent_FK being passed: " & Me.OpenArgs
        rs.FindFirst "InspectionEvent_FK = " & CLng(Me.OpenArgs)
            If rs.NoMatch Then  'it does not exist so you need to create it
                DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
                Me.InspectionEvent_FK = Me.OpenArgs
                Me.txtFinalProd_FK = intFinalProdID
                Me.NavigationButtons = False
                Me.cmdSaveLineStop.Enabled = False
                For Each ctl In Me.Controls
                    If ctl.Tag = "required" Or ctl.Tag = "secondary" Or ctl.Tag = "scrap" Then
                    ctl.Enabled = False
                    End If
                Next
                Me.cboLine1Workstation.Enabled = True
                Me.cboLine1Workstation.BackColor = vbYellow
                Me.cmdAddtlNotes.Visible = False
            End If
    Else
        If IsNull(Me.OpenArgs) Then
            Me.Filter = "LineStopBegin Is Not Null AND LineStopEnd Is Null"
            Me.FilterOn = True
            Me.NavigationButtons = True
                Me.cmdSaveLineStop.Enabled = False
                For Each ctl In Me.Controls
                    If ctl.Tag = "required" Or ctl.Tag = "secondary" Or ctl.Tag = "scrap" Then
                    ctl.Enabled = False
                    End If
                Next
                Me.cmdLineStopEnd.Enabled = True
                Me.txtLineStopEnd.Enabled = True
                Me.txtLineStopEnd.BackColor = vbYellow
                Me.cmdNotesAndPhotos.Visible = False
        End If
    End If
End Sub
 

Users who are viewing this thread

Top Bottom