Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check for an open form when opening a second form (Access 2k)

    Hello again

    I have a form in a database that can be opened from one of two points, if the form is opened from point 1 then I don't need it to do anything except accept the data input, however, if it is opened from point 2 I would like it to check a value in a combo box on the form containing the button that opens this form. I'm sure I've seen this on the forum before, but despite a few searches I've not found the old post.

    Essentially what I want to do is along these lines: -

    if form!A is open then
    control1 = forms!A!control2
    else
    end if

    I've tried looking for open forms, check open forms, active forms etc (in MSA help as well). What is the method / argument I need to search for?

    Thanks

    Ian

  2. #2
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check for an open form when opening a second form (Access 2k)

    Here's a way that I do this with a dummy text box.
    See attached it may help you.(sorry it's a bit rough)

    Open frmA, this will set txtTemp on the master form to "A".
    When the master form closes, it checks the txtTemp for it's value and setsfocus to whichever form opened it.
    Attached Files Attached Files

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Check for an open form when opening a second form (Access 2k)

    You can put the following function in a standard module:

    Function IsLoaded(ByVal strFormName As String) As Boolean
    ' Returns True if the form is loaded
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) Then
    IsLoaded = Forms(strFormName).CurrentView
    End If
    End Function

    Call it like this:

    If IsLoaded("FormA") Then
    ...
    Else
    ...
    End If

    Another possibility is to specify OpenArgs when opening a form:

    DoCmd.OpenForm FormName:="FormB", OpenArgs:=Me!Control2

    and to check OpenArgs in the OnOpen or OnLoad of FormB:

    Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
    Me.Control1 = OpenArgs
    End If
    End Sub

  4. #4
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check for an open form when opening a second form (Access 2k)

    Dave

    Thanks for the example, problem is I didn't mention that the forms are opened in dialogue mode, thus stopping anyone from 'playing' with them, and stopping any code executing from the previous form.... My mistake, I wonder if the code would work from a class module rather than from the button? The answer will be here some where <img src=/S/time.gif border=0 alt=time width=23 height=39> 2 <img src=/S/rtfm.gif border=0 alt=rtfm width=24 height=23>.

    Hans

    Excellent, two more new 'words' for my vocabulary. I'll give them both a try just to drive the lesson home.

    Thanks to both of you for taking the time to help me out again.

    Ian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •