• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

determine if a form is hidden what is the syntax

I need to open a popup form as hidden and determine on open of that form if it is opened in hidden mode.

What is the correct syntax.

I need to be able to open the popup as hidden, set the value of the combo, then execute the code on afterupdate of that combo, which sets the listbox values, then execute the code behind the button and keep this all hidden from the users and run in the background.  However I need to be able to use the same form in regular mode when it does require user inteface.  So I thought that if there is a way to check and see if the form has bee opened in hidden mode it can auto execute the necessary event procedures on that form.

Thanks,.
K
0
Karen Schaefer
Asked:
Karen Schaefer
  • 7
  • 5
  • 4
  • +1
2 Solutions
 
Bradley HaynesCommented:
This VBA code checks to see if a form is open . . . you modify the 'visibility' ( If F.Visible = False) property for hidden or not information.

Create a friend module called modForms.
Add a friend hashtable called Forms.

Friend Module modForms
    Friend Forms As New Hashtable()
End Module

In the Form_Load event for each form...

Me.Name = "FormName"
modForms.Forms.Add(Me.Name, Me)

This will add a reference in a central location accessible to all files in
the current project.

When you want to open a form...

Dim F As Form
If Not IsNothing(modForms.Forms("FormName")) Then
     F = modForms.Forms("FormName")
     If F.Visible = False Then
          F.Show()
     else
          F.BringToFront()
     End If
Else
     F = New FormNameObject()  
     F.Show()
End If
0
 
jjafferrCommented:

This is the Format to open in a hidden mode:

docmd.OpenForm "Your Form Name",acNormal,,,,acHidden

and this is the Format for a normal mode:

docmd.OpenForm "Your Form Name",acNormal

this way, you'll have ONE Form, but depending on how you open it, you control it's hidden/normal mode.

jaffer
0
 
Karen SchaeferAuthor Commented:
I know how to hide a form, it is the syntax to check if the form is opening up in hidden mode that I need to check.
b_haynes:
Not sure what you mean by 'Create a friend module called modForms.
Add a friend hashtable called Forms."

k
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
jjafferrCommented:
even if the Form is open in a hidden mode, you can call it for the normal mode, and it will open.
0
 
Karen SchaeferAuthor Commented:
I do not want to display the form  in normal mode for this instances I want to be able to execute the event procedures within the form without the user seeing what is happening, however, I still want to use the same form for the user in other instances.  Hence, checking to see if the form is hidden.

k
0
 
Rey Obrero (Capricorn1)Commented:
place this function in a module

Function isFormLoaded(ByVal sForm As String) As Boolean
    Const conObjStateClosed = 0
    Const conDesignView = 0
   
    If SysCmd(acSysCmdGetObjectState, acForm, sForm) <> conObjStateClosed Then
        If Forms(sForm).CurrentView <> conDesignView Then
            isFormLoaded = True
        End If
    End If

End Function


this will return true if form is open even if it is hidden

0
 
jjafferrCommented:
what I was trying to say is,
you can either check if the Form isloaded (like capricorn1 have shown), then run your code to that Form,
OR
Don't care if the Form is open/hidden,
just open the Form (again, that is if it was open) in a hidden mode, then run your code to that Form.

both ways it'll work.

jaffer
0
 
Karen SchaeferAuthor Commented:
Rey,

Your code is can only be used if there is only 1 form open at a time, Correct?

My code actually has a couple of forms open at the same time.  the original dialog where the necessary list box is filled and then executes based on that listboax, and a message form - where the message informs the user what is happening.  Will changing the dialog to Popup Modal and display the message else where on the screen?

k
0
 
jjafferrCommented:
kfschaefer1

Although you can take any direction that suites you,
but let me explain this again:

you don't have to know if your Form is open in a hidden mode,
so regardless of the above, use this code:

docmd.OpenForm "Your Form Name",acNormal,,,,acHidden
'execute your code after the above line.

this will ensure your Form is open in a hidden mode, and your code to run it will work.
0
 
Karen SchaeferAuthor Commented:
even if the event procedure is on the hidden form, how can you call that procedure from another form?
0
 
Rey Obrero (Capricorn1)Commented:
make the sub public

Public Sub xxx()

end sub


Forms!NameOfForm.xxx
0
 
Karen SchaeferAuthor Commented:
Rey,

the code for hidden form seems to always = true?
Public Function OpenWS_Prg()
    D = 1
    DoCmd.OpenForm "frmlookup", acNormal, , , acFormEdit, acDialog
    Forms![frmLookup].Visible = True
End Function

Function isFormHidden(ByVal sForm As String) As Boolean
    Const conObjStateClosed = 0
    Const conDesignView = 0
   
    If SysCmd(acSysCmdGetObjectState, acForm, sForm) <> conObjStateClosed Then
        If Forms(sForm).CurrentView <> conDesignView Then
            isFormHidden = True'<<<<<<<<<
        End If
    End If

End Function


If isFormHidden("FrmLookup") Then
    If gPrgID <> 0 Then
        Me.cmbProgram = gPrgID 'rs.Fields("Program_ID").Value
        rs.Close
        Set rs = Nothing
        cmbProgram_AfterUpdate
        For I = 0 To Me.lstAPNo.ListCount - 1
            Me.lstAPNo.Selected(I) = True
        Next I
        cmdGenerateFTIR
    End If
Else
    strSQL = "SELECT Program_ID FROM TA_Program WHERE (Program_ID = GetgPrgID())"
    Set rs = CurrentDb.OpenRecordset(strSQL)
    For Each frm In Forms
      If frm.Name <> "frmlookup" Then DoCmd.Close acForm, frm.Name
    Next frm

0
 
Rey Obrero (Capricorn1)Commented:
try closing  FrmLookup  and type the following in the immediate window then hit enter


?isformhidden("FrmLookup")


it will give you False
0
 
Karen SchaeferAuthor Commented:
Tried your suggestion and yes it displays the true false, however, I will work the first time I open the from fom the switchboard.  When I access the popup form from the other source dataentry form, then thru the switchboard again, it wants to open the popup in hidden mode - what am I missing.

here is the code for  swtichboard
Public Function OpenWS_Prg()
    D = 1
    If isFormHidden("frmlookup") = False Then
        DoCmd.OpenForm "frmlookup", acNormal, , , acFormEdit, acDialog
    End If
End Function

here is the code for the popup.

If isFormHidden("FrmLookup") Then
    Debug.Print isFormHidden("FrmLookup")
    If gPrgID <> 0 Then
        Me.cmbProgram = gPrgID
        cmbProgram_AfterUpdate
        For I = 0 To Me.lstAPNo.ListCount - 1
            Me.lstAPNo.Selected(I) = True
        Next I
        cmdGenerateFTIR
    End If
Else
    strSQL = "SELECT Program_ID FROM TA_Program WHERE (Program_ID = GetgPrgID())"
    Set rs = CurrentDb.OpenRecordset(strSQL)
    For Each frm In Forms
      If frm.Name <> "frmlookup" Then DoCmd.Close acForm, frm.Name
    Next frm

    If gPrgID <> 0 Then
        Me.cmbProgram = rs.Fields("Program_ID").Value
        rs.Close
        Set rs = Nothing
        cmbProgram_AfterUpdate
    End If
    Me.cmbProgram.SetFocus
    gAPNo = vbNullString
    If D = 1 Then
        Me.cmdOpenWS.Visible = True
        Me.cmdOpenWA.Visible = False
    Else
        Me.cmdOpenWS.Visible = False
        Me.cmdOpenWA.Visible = True
    End If
End If
End Sub

As you can see that on open of the DAtaentry form I am closing all forms  on open

Private Sub cmdNewMasterWS_Click()
On Error GoTo Err_cmdNewMasterWS_Click

   D = 0
    gWSNo = Nz(Me.cmbWSNoPt1) & Nz(Me.cmbWSNoPt2) & Nz(Me.cmbWSNoPt3) & Nz(Me.txtWSNoPt4)
    strSQL = "SELECT * FROM TA_WS where WS_No not Like '*" & gWSNo & "*'"
    Set rs = CurrentDb.OpenRecordset(strSQL)
    If rs.EOF = False Then
        GoTo ResumeNext:
    Else
        Select Case MsgBox("WS_NO ALREADY EXISTS, DO YOU WISH TO VIEW THE WORK STATEMENT FOR " & gWSNo & "?  " _
                           & vbCrLf & "                              Select No, to make another selection." _
                           , vbYesNo Or vbCritical Or vbDefaultButton1, "WARNING!!!!!!!!!!!!")
            Case vbYes
                GoTo ResumeNext
            Case vbNo
                Me.cmbWSNoPt1.SetFocus
                Me.txtWSNoPt4 = vbNullString
                GoTo Exit_cmdNewMasterWS_Click
       End Select
    End If
ResumeNext:

        stDocName = "frmWS_Dataentry"
        DoCmd.OpenForm stDocName, acNormal, "TempQry", , acFormAdd, acWindowNormal
        Forms![frmWS_Dataentry]!WS_NO.SetFocus
    For Each frm In Forms
      If frm.Name <> "frmWS_Dataentry" Then DoCmd.Close acForm, frm.Name
    Next frm

Exit_cmdNewMasterWS_Click:
    Exit Sub

Err_cmdNewMasterWS_Click:
    MsgBox Err.Description
    Resume Exit_cmdNewMasterWS_Click
   
End Sub

Why is this working the first time and not the next time.  Acts like the form is still open.
k
0
 
Karen SchaeferAuthor Commented:
Thanks to all who assisted, however, decided to go another route by passing a variant, based on the set variant I ran the specific code.

Thanks,

Karen
0
 
Rey Obrero (Capricorn1)Commented:
based on the requirement of the original question, i think a solution was provided.
0
 
jjafferrCommented:
capricorn1 is correct,
my solution works too.

jaffer
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 7
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now