Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2003
    Location
    Spokane, WA
    Posts
    81

    Question Unanswered: Query Returns Nothing Message

    I have a query set up that will open a certain form.

    Is there a way that if their input does not match anything to bring up a message rather than a blank form?

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    Put code in the load event of the form

    If Me.Recordset.RecordCount=0 then

    MsgBox "No records found"
    Unload Me

    End If
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  3. #3
    Join Date
    Sep 2003
    Location
    Spokane, WA
    Posts
    81

    Unhappy

    I get the message box ok, but upon clicking the button to proceed, get the following message;

    ******
    Run time error '361:

    Can't load or unload this object
    ******

    In the debug window the "unload me" statement is highlighted.

  4. #4
    Join Date
    Sep 2003
    Location
    Spokane, WA
    Posts
    81

    Exclamation Works, but...

    Ok the debug window thing has been resolved. And the message window works ok.

    But after clicking "Ok", a new form still pops up. Anyway to redirect back to the main switchboard?

  5. #5
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    What about making a nice looking form that exactly matches the size and positioning of the form in question.

    You could put a label on the form like No Records Found and put a macro or code on a label that closes your main form and the form that opened with the No Records Found and then opens your switchboard.

    Mike

  6. #6
    Join Date
    Sep 2003
    Location
    Spokane, WA
    Posts
    81
    I can see how that would work, but am looking for something more simple. Like a suggestion or two for the coding to automatically close the form.

  7. #7
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    Quote Originally Posted by jacque427
    I can see how that would work, but am looking for something more simple. Like a suggestion or two for the coding to automatically close the form.
    Are you wanting the Message Box/Form to open and automatically close after a few seconds. If so, you could do what I suggested above and then put the macro or code "On Timer" and then you can select how long the "warning" form will stay open.

    DoCmd.Echo False, ""
    DoCmd.OpenForm "Switchboard", acNormal, "", "", acEdit, acNormal
    DoCmd.Close acForm, "MainForm"
    DoCmd.Close acForm, "WarningForm"

    The above is just a macro that I converted in Access 95.

    But macro or code, placing it "On Timer" is what automatically close the form.

    The On Timer is 1000 for each second, that is, if you wanted the warning to sit there for 5 seconds you enter 5000.

    You could also place that code or macro on your On Timer for your MainForm and have a SetValue action that sets the TimerInterval at 0 when there are no records. When set at 0 the macro or code will not run and so the form will remain open.

    You could ake a simple little form that opens when there are no records and with a message The MainForm will Close in 5 Seconds

    Mike

  8. #8
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    Try putting the code in the Activate event instead of the Load event:

    If Me.Recordset.RecordCount=0 then

    MsgBox "No records found"
    Unload Me

    End If
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

Posting Permissions

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