Using the IsLoaded() function in Access 2000 causes error, but not in Access 2002

D

Dave

Hi,

I'm trying to use the IsLoaded() function in Access 2000. I have the
function defined in a module, and I'm calling it into a sub procedure.
This works perfectly when running my app from within Access 2002
(Access 2000 format), but when I run my app in Access 2000 and the sub
procedure runs, I get a message box that reads:
______________________

"Compile error:

Variable not defined"
______________________

and "acCurViewDesign" is highlighted in the module during the
debugging process.

This happened not only in my app, but when I tried to open the
Suppliers form from the Northwind Sample database within Access 2000.
The only version of Northwind I have is what came with Access 2002.

So, is there a way to define this variable and get this function to
work in Access 2000, and if so, how do I do it, or is there some other
piece of code/function that will work in Access 2000 to test whether
or not a certain form is currently open/loaded?

Thanks,

Dave
 
G

Graham Mandeno

Hi Dave

The constant AcCurrentView constants don't exist in the Access 2000 object
library.

No problem - just define it yourself in the function:
Const acCurViewDesign = 0
 
D

Dave

Thanks for the quick answer Graham. This allowed most of the code to
run now, except it's still showing an error at the end. I'm getting
the following error now:
_____________________________

Run-time error '438':

Object doesn't support this property or method
_____________________________

After clicking the debug button, it displays the following function in
break mode with the line that has <<Y>> at the end highlighted in
yellow:
_____________________________

Option Compare Database
Option Explicit
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or
Datasheet view.
Dim oAccessObject As AccessObject
Const acCurViewDesign = 0
Set oAccessObject = CurrentProject.AllForms(strFormName)
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then <<Y>>
IsLoaded = True
End If
End If

End Function
_____________________________

Did I put the "Const acCurViewDesign = 0" line of code in the wrong
place? Any ideas?

Graham Mandeno said:
Hi Dave

The constant AcCurrentView constants don't exist in the Access 2000 object
library.

No problem - just define it yourself in the function:
Const acCurViewDesign = 0

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Dave said:
Hi,

I'm trying to use the IsLoaded() function in Access 2000. I have the
function defined in a module, and I'm calling it into a sub procedure.
This works perfectly when running my app from within Access 2002
(Access 2000 format), but when I run my app in Access 2000 and the sub
procedure runs, I get a message box that reads:
______________________

"Compile error:

Variable not defined"
______________________

and "acCurViewDesign" is highlighted in the module during the
debugging process.

This happened not only in my app, but when I tried to open the
Suppliers form from the Northwind Sample database within Access 2000.
The only version of Northwind I have is what came with Access 2002.

So, is there a way to define this variable and get this function to
work in Access 2000, and if so, how do I do it, or is there some other
piece of code/function that will work in Access 2000 to test whether
or not a certain form is currently open/loaded?

Thanks,

Dave
 
D

Dirk Goldgar

Dave said:
Thanks for the quick answer Graham. This allowed most of the code to
run now, except it's still showing an error at the end. I'm getting
the following error now:
_____________________________

Run-time error '438':

Object doesn't support this property or method
_____________________________

After clicking the debug button, it displays the following function in
break mode with the line that has <<Y>> at the end highlighted in
yellow:
_____________________________

Option Compare Database
Option Explicit
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or
Datasheet view.
Dim oAccessObject As AccessObject
Const acCurViewDesign = 0
Set oAccessObject = CurrentProject.AllForms(strFormName)
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then <<Y>>
IsLoaded = True
End If
End If

End Function
_____________________________

Did I put the "Const acCurViewDesign = 0" line of code in the wrong
place? Any ideas?

I'm afraid the CurrentView property doesn't exist for AccessObject in
Access 2000, either. You can modify the above function to look in the
forms collection for strFormName (after verifying that it's loaded) and
check the form's CurrentView property, but I've found the old, reliable
SysCmd method to be more efficient (and it works in Access 97, too).
Here's the version of the IsLoaded function that I use (not my own code,
though):

'----- start of code -----
Function IsLoaded(ObjectName As String, _
Optional ObjectType As Integer = acForm) _
As Boolean

If SysCmd(acSysCmdGetObjectState, ObjectType, ObjectName) =
acObjStateOpen Then
Select Case ObjectType
Case acForm
If Forms(ObjectName).CurrentView <> 0 Then IsLoaded =
True
Case Else
IsLoaded = True
End Select
End If

End Function

'----- end of code -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top