None working "simple Code" on close event? (1 Viewer)

L'apprentis

Redcifer
Local time
Today, 09:59
Joined
Jun 22, 2005
Messages
177
I have witten a code in the close event of a "Primary" form that would update a Combo boxe on a "secondary" form only if the "secondary" form is open.
ie:

Code:
Private Sub Form_Close()
If Forms!frmEnquiry.Open Then
Forms!frmEnquiry!CboCustomer.Requery
Else
DoCmd.Close
End If
End Sub

This code keeps giving me an error, is anybody has got any idea why?
Thanks in advance.
 

boblarson

Smeghead
Local time
Today, 09:59
Joined
Jan 12, 2001
Messages
32,059
Yes, the part you wrote about:
Code:
Forms!frmEnquiry.Open
is not valid code checking for the state of a form. I don't know what that code would be, and hopefully someone will share that with us, but that is why you're getting an error.
 

ghudson

Registered User.
Local time
Today, 12:59
Joined
Jun 8, 2002
Messages
6,194
IsLoaded is what you want. Access 2003 finally built the IsLoaded() function into Access 2003. Anything older then you will have to use the custom IsLoaded () function that Microsoft includes with the Norwind sample that comes will all versions of Access. Search around the forum for it is posted here as well.

Thanx Rich!
 
Last edited:

L'apprentis

Redcifer
Local time
Today, 09:59
Joined
Jun 22, 2005
Messages
177
umm....
I have added the following is loaded code in my modul
Code:
Function IsLoaded(ByVal strFormName As String) As Boolean
 ' Returns True if the specified form is open in Form view or Datasheet view.
    
    Const conObjStateClosed = 0
    Const conDesignView = 0
    
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
        If Forms(strFormName).CurrentView <> conDesignView Then
            IsLoaded = True
        End If
    End If
    
End Function
but I still get an error message with the following code:
Code:
Private Sub Form_Close()
If IsLoaded(FrmEnquiry) Then
Forms!FrmEnquiry!CboCustomer.Requery
Else
DoCmd.Close
End If
End Sub
Where "FrmEnquiry" is a variable not defined, have you got any idea why?
 

john471

Registered User.
Local time
Tomorrow, 02:59
Joined
Sep 10, 2004
Messages
392
You need to pass the name of the form as a string.

Private Sub Form_Close()
If IsLoaded("FrmEnquiry") Then 'note : enclosed in quotes

or

Private Sub Form_Close()
dim frmEnquiry as string
frmEnquiry = "TheNameOfYourForm"
If IsLoaded(FrmEnquiry) Then 'not enclosed in quotes i.e. a variable - the variable contains the string.
 

Users who are viewing this thread

Top Bottom