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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

limiting navigation to forms

Status
Not open for further replies.

jommyjet

Technical User
May 19, 2003
49
US
Is there a way to limit navigation to forms?. If a user wants to open a report, do it through a form, else they shouldn't be there. thanks
 
You can put code in the report's Open() event which can check if a form is loaded. If a form is not loaded, you can Cancel the report opening.

I believe if you're using Access 2000 or higher, the isLoaded function is built-in (can't verify directly), but if you need a custom-built isLoaded() function, the threads below will provide some examples:



--
Find common answers using Google Groups:

Corrupt MDBs FAQ
 
thanks. can you use isloaded as a general setting, implying all data objects?
 
Here's what I was looking for Access2000+:

Code:
Application.CurrentProject.AllForms("Form1").IsLoaded


For non-forms, here's one module:



Code:
Option Compare Database
Option Explicit

'objectExists()
'
'For tables, queries and modules, this function returns true if they EXIST.
'For forms and reports, this function returns true if they are OPEN.
Public Function objectExists(objType As String, objName As String) As Boolean
    Select Case objType
    Case acTable
        objectExists = tableExists(objName)
    Case acQuery
        objectExists = queryExists(objName)
    Case acForm
        objectExists = formExists(objName)
    Case acReport
        objectExists = reportExists(objName)
    Case acModule
        objectExists = moduleExists(objName)
    Case Else
        objectExists = False
    End Select
End Function

Public Function tableExists(tableName As String) As Boolean
    On Error GoTo sub_Error
    Dim tmp As String
    
    tmp = DBEngine(0)(0).TableDefs(tableName).Name
    tableExists = True
    
sub_Exit:
    Exit Function
    
sub_Error:
    tableExists = False
    GoTo sub_Exit
End Function

Public Function queryExists(queryName As String) As Boolean
    On Error GoTo sub_Error
    Dim tmp As String
    
    tmp = DBEngine(0)(0).QueryDefs(queryName).Name
    queryExists = True
    
sub_Exit:
    Exit Function
    
sub_Error:
    queryExists = False
    GoTo sub_Exit
End Function

Public Function formExists(formName As String) As Boolean
    On Error GoTo sub_Error
    Dim tmp As String
    
    tmp = Forms(formName).Name
    formExists = True
    
sub_Exit:
    Exit Function
    
sub_Error:
    formExists = False
    GoTo sub_Exit
End Function

Public Function reportExists(reportName As String) As Boolean
    On Error GoTo sub_Error
    Dim tmp As String
    
    tmp = Reports(reportName).Name
    reportExists = True
    
sub_Exit:
    Exit Function
    
sub_Error:
    reportExists = False
    GoTo sub_Exit
End Function

Public Function moduleExists(moduleName As String) As Boolean
    On Error GoTo sub_Error
    Dim tmp As String
    
    tmp = Modules(moduleName).Name
    moduleName = True
    
sub_Exit:
    Exit Function
    
sub_Error:
    moduleName = False
    GoTo sub_Exit
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top