Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stop form opening based on query (2000)

    Hi,
    How would I stop a form from opening, dependant upon whether or not the query that it is based on returns any records?
    Basically I have a main form with a command button on it. The On Click event of this button opens the said form, which shows various data dependant on criterias. Ideally I'd like to stop this form from opening, if there is no data to display.

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

    Re: Stop form opening based on query (2000)

    You can test in the On Click code, using DCount:

    Private Sub cmdSomething_Click()
    If DCount("*", "QueryName", "WhereCondition") > 0 Then
    DoCmd.OpenForm ...
    End If
    End Sub

    where QueryName is the name of the query and WhereCondition is a string specifying the criteria.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stop form opening based on query (2000)

    Thanks Hans, works a treat!
    Is it also possible to turn of the pop-up properties of a form once that form is no longer needed? I have two pop-up forms used at different times, and one one triggers, this seems to trigger the other.

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

    Re: Stop form opening based on query (2000)

    Sorry, can you try to explain that again? I don't understand.

  5. #5
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stop form opening based on query (2000)

    Sorry, I have a main form with two pop-up forms on it. This is where I have set the PopUp to Yes and Modal to Yes. One is a pop-up calendar, the other is a password form, for access to further data. So the user generally uses the calendar pop-up to fill certain fields, and the administrators use the password form to access audit trails, usage statistics etc. For some reason if a previous pop-up form has been opened, i.e. FrmPassword, and then the user uses the pop-up calendar, frmPassword pops up over this once it has opened.
    I've tried the obvious
    DoCmd.Close acform, Me.Name
    on the unload event of the form, but this doesn't seem to resolve it. I'm slightly puzzled............... <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  6. #6
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Stop form opening based on query (2000)

    If the pop ups are set to model = yes, then you should not be able to activate other forms or options until the pop up form is closed. Are you sure they are model?
    Regards,
    Rudi

  7. #7
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stop form opening based on query (2000)

    I've managed to work around this, so problem resolved, but thank you for your help...........

Posting Permissions

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