Results 1 to 3 of 3
  1. #1
    ser01 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Posts
    64

    Code to check if form1 is open, then open then opoen form 2

    I need a symple piece fo code that could be inserted in a command button's click event. It would check if form1 is opened, and if it is then open form2. Should be easy foar a VBA programmer, very difficult for me though


    Thank you in advance.
    Last edited by ser01; 02-26-2010 at 08:14 AM.

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931

    Form whether form is open.

    Open a module in access and paste the following function:

    Public Function funIsLoadedForm(ByVal strFormName As String) As Boolean
    ' Returns True if the specified form is open in Form view or Datasheet view.
    On Error GoTo Error_funIsLoadedForm
    Const conObjStateClosed = 0
    Const conDesignView = 0
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
    If Forms(strFormName).CurrentView <> conDesignView Then
    funIsLoadedForm = True
    End If
    End If

    Exit_funIsLoadedForm:
    Exit Function

    Error_funIsLoadedForm:
    MsgBox "Error in funIsLoadedForm: " & Err.Number & " - " & Err.Description
    Resume Exit_funIsLoadedForm

    End Function

    Now open the from on which you have the command button from where you want to check whether say Form1 is open.

    If funIsLoadedForm("Form1") = True then
    Do whatever you have to do
    End If

    type the above code in your onClick event in the command button.

    please mark this thread if this solves your problem.

  3. #3
    ser01 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Posts
    64
    Quote Originally Posted by maximus View Post
    Open a module in access and paste the following function:

    Public Function funIsLoadedForm(ByVal strFormName As String) As Boolean
    ' Returns True if the specified form is open in Form view or Datasheet view.
    On Error GoTo Error_funIsLoadedForm
    Const conObjStateClosed = 0
    Const conDesignView = 0
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
    If Forms(strFormName).CurrentView <> conDesignView Then
    funIsLoadedForm = True
    End If
    End If

    Exit_funIsLoadedForm:
    Exit Function

    Error_funIsLoadedForm:
    MsgBox "Error in funIsLoadedForm: " & Err.Number & " - " & Err.Description
    Resume Exit_funIsLoadedForm

    End Function

    Now open the from on which you have the command button from where you want to check whether say Form1 is open.

    If funIsLoadedForm("Form1") = True then
    Do whatever you have to do
    End If

    type the above code in your onClick event in the command button.

    please mark this thread if this solves your problem.
    Thank you very much, works great!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA Open Form If - Else
    By Bruce in forum Forms
    Replies: 3
    Last Post: 02-11-2010, 12:57 PM
  2. Replies: 1
    Last Post: 12-01-2009, 09:00 AM
  3. Replies: 1
    Last Post: 06-04-2009, 07:43 AM
  4. Form will not open
    By dserbanescu in forum Forms
    Replies: 0
    Last Post: 01-09-2008, 09:48 AM
  5. Open form in another database
    By Karyn-2000 in forum Forms
    Replies: 0
    Last Post: 04-19-2006, 10:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums