fIsloaded Function

E

Eric

Hi guys,

Can someone help me here? I'm having a really hard time
with this fIsLoaded Function. I have passed this on to the
IsLoaded Function, but I want the fIsloaded to fall back
on my original Forms Class module to see if a form is open
or not. What am I doing wrong????? Here's my code.

In the Forms Class Module:

Private Sub Form_Open(Cancel As Integer)

Dim UserID As Long, ACode As Integer, strFormName As String

strFormName = "frmAnalysisFilm"
UserID = Forms!frmPassword!cboEmployee
ACode = DLookup("AccessLevelID", "tblUser", "ID = " &
UserID)

Me.Mach.Enabled = False
Me.Product.Enabled = False
Me.Date_Scrapped.Enabled = False
Me.DateProduced.Enabled = False
Me.Reason.Enabled = False
Me.Operator.Enabled = False
Me.PoundsScrapped.Enabled = False
Me.Skid.Enabled = False
Me.Roll.Enabled = False
Me.ScrappedBy.Enabled = False

If ACode < 1 Then
Me.Command20.Enabled = False
Me.Command21.Enabled = False
Me.Command22.Enabled = False
Me.Command24.Enabled = False
Exit Sub
Else: End If

Call fIsLoaded(strFormName)

If fIsLoaded = -1 Then
Me.Mach.Enabled = True
Me.Product.Enabled = True
Me.Date_Scrapped.Enabled = True
Me.DateProduced.Enabled = True
Me.Reason.Enabled = True
Me.Operator.Enabled = True
Me.PoundsScrapped.Enabled = True
Me.Skid.Enabled = True
Me.Roll.Enabled = True
Me.ScrappedBy.Enabled = True
Me.Command23.Enabled = False
Else: End If

DoCmd.Maximize

End Sub

Here's in a normal module:

Function fIsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName)
<> 0 Then
If Forms(strFormName).CurrentView <> 0 Then
fIsLoaded = True
End If
End If
End Function
 
S

Sandra Daigle

You are using the function incorrectly. Either you test the return value
within the statement in which it is referenced or you save it's return value
in a local variable which you later test. Here's how to correct your code:

If fIsLoaded(strFormName)=true Then
Me.Mach.Enabled = True
Me.Product.Enabled = True
Me.Date_Scrapped.Enabled = True
Me.DateProduced.Enabled = True
Me.Reason.Enabled = True
'rest of code

Alternatively, you can use the implicit comparison to true:

If fIsLoaded(strFormName) Then
' Rest of code


The function should probably also be modified to return a boolean value

Function fIsLoaded(ByVal strFormName As String) As Boolean
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
If Forms(strFormName).CurrentView <> 0 Then
fIsLoaded = True
End If
End If
End Function
 
G

Guest

If fIsLoaded(strFormName)=true Then
Me.Mach.Enabled = True
Me.Product.Enabled = True
Me.Date_Scrapped.Enabled = True
Me.DateProduced.Enabled = True
Me.Reason.Enabled = True
'rest of code

Alternatively, you can use the implicit comparison to true:

If fIsLoaded(strFormName) Then
' Rest of code

Which is better? The first or second?
 
S

Sandra Daigle

I'm not sure whether you could say that one is better than the other but I
prefer the second since it requires less typing ;-)

In Access97 there was a bug involving a very specific type of implicit
boolean comparison that could create a situation where you are unable to
quit Microsoft Access. (http://support.microsoft.com/?kbid=190074). AFAIK
this problem was corrected in A2000 and above. I use implicit boolean
comparisons all the time.
 

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

Top