Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to control if form is present ?

Status
Not open for further replies.

Schaap

Technical User
Jul 6, 2004
54
NL
Is it possible to detect if a form is present at the start of the database/startform without displaying it ?
And how will that be done.

So I can use to make it not possible (at a easy way) to delete a form of the database(GUI)!

I can imagine that I take a variable that will be set only on the 'not deleting form' and check that. But then I have to open/load the form first! and that's not possible.
Please does anyone have a clue ?

 
I would imagine you could place code in your _Open or _Load event of your form that you want to open and show when the database first opens that would be something like the following:

Code:
Private Sub frmForm1_Open()
  DoCmd.OpenForm Forms!frmForm2
  Forms!frmForm2.Visible = False
End Sub

I'm sure there'd be another way to do it, but I would imagine this would work just as well.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
kjv1611,

your solution is not working.
With your code I get an error.
I changed Forms!frmForm2.Visible = False into
Me.Formname2 = False.
But even with this doesn't make the form invisible !!!

The form2 has a timeinterval, and that's still working
 
You need to use the isLoaded function.

Code:
If CurrentProject.AllForms(your form name).IsLoaded = true Then
     some code!!!
else
     some code!!!
end if

good luck.

 
Not entirely sure what you want to do, but if you want to see whether or not a form exists in your database then you can use this function:
Code:
Function ObjectExists(strObjectType As String, strObjectName As String) As Boolean
     Dim db As Database
     Dim tbl As TableDef
     Dim qry As QueryDef
     Dim i As Integer
     
     Set db = CurrentDb()
     ObjectExists = False
     
     If strObjectType = "Table" Then
          For Each tbl In db.TableDefs
               If tbl.NAME = strObjectName Then
                    ObjectExists = True
                    Exit Function
               End If
          Next tbl
     ElseIf strObjectType = "Query" Then
          For Each qry In db.QueryDefs
               If qry.NAME = strObjectName Then
                    ObjectExists = True
                    Exit Function
               End If
          Next qry
     ElseIf strObjectType = "Form" Or strObjectType = "Report" Or strObjectType = "Module" Then
          For i = 0 To db.Containers(strObjectType & "s").Documents.Count - 1
               If db.Containers(strObjectType & "s").Documents(i).NAME = strObjectName Then
                    ObjectExists = True
                    Exit Function
               End If
          Next i
     ElseIf strObjectType = "Macro" Then
          For i = 0 To db.Containers("Scripts").Documents.Count - 1
               If db.Containers("Scripts").Documents(i).NAME = strObjectName Then
                    ObjectExists = True
                    Exit Function
               End If
          Next i
     Else
          MsgBox "Invalid Object Type passed, must be Table, Query, Form, Report, Macro, or Module"
     End If
     
End Function

Call it like
Code:
If ObjectExists("Form","frmFooBar")=True Then
'Do whatever you like
End If
It can also check for any other Access Object.

If this isn't what you want, could you explain a little more about what you are trying to do and why.

Cheers

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
If the form has a time interval, I would assume so long as the form is open. Maybe you could add in some code that basically says in the timer event:
Code:
Private Sub Form_Timer()
  If Form.Visible = True Then
     ~And put your code here
  End If
End Sub


Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top