• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Form close/reopen to filter criteria

Experts,
In the below code I woudl like to know if under the ELSE part I can add something that looks to see if the open form "frmLetterOfCredit_Cont" is already opened to the filter criteria and if so then dont reopen it like it is doing now?  If the form is already open to the filter criteria currently it closes and then reopens and it takes too much time because the network is slow.  

So basically if the form "frmLetterOfCredit_Cont" is already opened to OpenArgs:=Me.ID & ";" & Me.cboEndUserID then dont close it and reopen...just bring that form to the front and if NOT then close and reopen.

Private Sub btnOpenLCForm_Click()

    If CurrentProject.AllForms("frmLetterOfCredit_Cont").IsLoaded = False Then
         DoCmd.OpenForm "frmLetterOfCredit_Cont", , , , , , OpenArgs:=Me.ID & ";" & Me.cboEndUserID
        'Cancel = True
    Else
        DoCmd.Close acForm, "frmLetterOfCredit_Cont"
        DoCmd.OpenForm "frmLetterOfCredit_Cont", , , , , , OpenArgs:=Me.ID & ";" & Me.cboEndUserID

    End If
   
End Sub
0
pdvsa
Asked:
pdvsa
  • 2
1 Solution
 
peter57rCommented:
If CurrentProject.AllForms("frmLetterOfCredit_Cont").IsLoaded = False Then
         DoCmd.OpenForm "frmLetterOfCredit_Cont", , , , , , OpenArgs:=Me.ID & ";" & Me.cboEndUserID
        'Cancel = True

elseif forms!frmletterofcredit.someidcontrol= me.id and forms!frmletterofcredit.anotheridcontrol= Me.cboEndUserID then
' do nothing, already correct

Else
        DoCmd.Close acForm, "frmLetterOfCredit_Cont"
        DoCmd.OpenForm "frmLetterOfCredit_Cont", , , , , , OpenArgs:=Me.ID & ";" & Me.cboEndUserID
End If
0
 
peter57rCommented:
Obviously you must use your own control names in the above mod.
0
 
Rey Obrero (Capricorn1)Commented:
try this, better to check the value of .filter property of the form

Private Sub btnOpenLCForm_Click()

    If CurrentProject.AllForms("frmLetterOfCredit_Cont").IsLoaded = False Then
         DoCmd.OpenForm "frmLetterOfCredit_Cont", , , , , , OpenArgs:=Me.ID & ";" & Me.cboEndUserID
        'Cancel = True
    Else
    
        If Forms!frmLetterOfCredit_Cont.Filter = "[ProjectID] = " & Me.ID & " AND [EndUserID] = " & Me.cboEndUserID Then
            Forms!frmLetterOfCredit_Cont.SetFocus
            Else
            DoCmd.Close acForm, "frmLetterOfCredit_Cont"
            DoCmd.OpenForm "frmLetterOfCredit_Cont", , , , , , OpenArgs:=Me.ID & ";" & Me.cboEndUserID
        End If
    End If

End sub

Open in new window

0
 
pdvsaProject financeAuthor Commented:
Cap, that worked perfectly.  I was just about to respond to Peter.

Pdvsa
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now