Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Add message box to form (A2K/SR1 and AXP)

    I have a form that we use to mark the courses that students have completed. The user scrolls through the list of 230-plus courses and checks a box for each course a given student completed in the current round of training. The next step is to print a list of courses that will be available to the student during the next round of training--the ones we marked as "taken" will not appear on the new list.

    When the user finishes working with that student's record, he or she is supposed to UNcheck those courses. I've put a button on the form that takes care of that chore--the user clicks on the button, and all those check marks go away. (I can thank the good people on this forum for showing me how to create that button! <img src=/S/salute.gif border=0 alt=salute width=15 height=20> That thread begins with my post number 186235.) Trouble is, sometimes we forget to click on that button. When the next user comes along, he may miss some of the checked boxes, and the next student winds up with an incorrect training plan.

    So, methinks what I need is a message box that will pop up when the user tries to close the form. Say the user clicks on the Close button. Immediately, up pops a message box that asks, "Have you cleared the 'Taken' field?" Then there'd be two buttons: One labeled "Yes, thank you!" and another labeled "Oops! Thanks for reminding me!" When you click on "Yes...," the message box and the form close. When you click on "Oops!" the message box goes away to permit the user to deal with the unfinished business.

    Can someone help me set this up, please? Thanks!

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

    Re: Add message box to form (A2K/SR1 and AXP)

    Why not clear the check boxes automatically when the user closes the form? You can call the button-click routine in the OnClose or OnUnload event of the form:

    Private Form_Close()
    ' Substitute the name of the 'Clear check boxes' button
    cmdClearCheckBoxes_Click
    End Sub

    With a standard MsgBox, you can display Yes and No buttons and a Question mark icon, but you can't customize the button captions. Here is code for the OnUnload event of the form that cancels the unloading if the user answers No:

    Private Sub Form_Unload(Cancel As Integer)
    If MsgBox("Have you cleared the 'Taken' field?", vbQuestion + vbYesNo) = vbNo Then
    Cancel = True
    End If
    End Sub

    If you want a more fancy message box, you must create a small form with the appropriate labels and buttons, and call this as a dialog, or you can download the custom MsgBox form from <post#=129656>post 129656</post#> by Tom Bushaw.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Add message box to form (A2K/SR1 and AXP)

    Clearing the check boxes upon closing the form makes PERFECT sense! Now, let me make sure I understand your post.

    If I use the code you furnished, when the user clicks the "close" button (X), that action will automatically call the same routine that I've built into the button that I labeled "Clear 'Taken' Field"? Well, it seems to me I could make things even simpler for the user by eliminating the extra button altogether and setting things up to clear the checkboxes on clicking the close button...right? How would we modify the code to make this happen?

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

    Re: Add message box to form (A2K/SR1 and AXP)

    Lucas,

    The Form_Close event occurs when the form is closed, whether the user clicks the close button (x) in the upper right corner, or types Ctrl+F4, or clicks a command button that executes DoCmd.Close. So any code in the Form_Close event will be run, whatever way the form is closed.

    I don't know if there are situations where the user would want to clear the check boxes while working in the form, for example to start over.

    If so, leave the command button in place and use the Form_Close event to call the button click routine.

    Otherwise, you can cut (or copy) the code from the button click routine and paste it into the Form_Close event. Then, you can delete the button click routine from the form module and the command button from the form itself.

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Add message box to form (A2K/SR1 and AXP)

    Yes, now that you mention it, there are times when the user will want to clear all the check boxes and start over without closing the form. That's a good point. So...what I think I'll do is copy the button click routine from the command button into the Form_Close event. That way, the check boxes will get cleared either way. Thanks again!

Posting Permissions

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