Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Close blank form (2002 (10.2616.2625))

    <img src=/S/aflame.gif border=0 alt=aflame width=16 height=16> I need to have a form not be able to close until all entries are filled out.
    I have tried the required option on the table and forms but this lets the form close and not save the record (which in this case is really bad since the person entering the data would not know the info was not saved).
    I need the form to stay opened until all information is filled out then it can close.
    thanks in advance....

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close blank form (2002 (10.2616.2625))

    You need to use the BeforeUpdate event of the form to test the fields and see that everything is complete. BeforeUpdate has a Cancel argument, so if the fields are not complete, you can set Cancel = True and give the user a messagebox telling them they have to complete the data. If you cancel the BeforeUpdate, the form will not close. However, you need to give them the option of discarding the current data and undoing anything they entered so that they can close the form.
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close blank form (2002 (10.2616.2625))

    How do I do that part.... I know very little about VB

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close blank form (2002 (10.2616.2625))

    You're asking about something that can only be done properly with VBA code in Access. If you plan on using Access seriously, I'd suggest you get acquainted with VBA immediately, since it's the only way to make Access sit up and do tricks.

    If you open the form in design view and bring up the properties dialog, you'll see an event called Before Update. If you select [Event Procedure] from the dropdown, the wizard will automatically insert the shell of a BeforeUpdate event in the form's module. Start there, and then post back and ask specific questions.
    Attached Images Attached Images
    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close blank form (2002 (10.2616.2625))

    The VBA part is where I am getting stuck. All I want to do is look to see if everything is filled out.
    If it is all filled out then the form can close
    If not you can cancel the record or finish filling out the form and close.

    Thanks for all your help

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

    Re: Close blank form (2002 (10.2616.2625))

    You can use the following as a "template" for the code Charlotte meant. You will have to adapt it to your situation.

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.txtField1) Then
    If MsgBox("You didn't fill in Field1. Abandon record?", vbQuestion + vbYesNo) = vbYes Then
    Me.Undo
    Else
    Cancel = True
    Me.txtField1.SetFocus
    End If
    ElseIf IsNull(Me.txtField2) Then
    If MsgBox("You didn't fill in Field2. Abandon record?", vbQuestion + vbYesNo) = vbYes Then
    Me.Undo
    Else
    Cancel = True
    Me.txtField2.SetFocus
    End If
    End If
    End Sub

  7. #7
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close blank form (2002 (10.2616.2625))

    I have tried that code you gave me every way I can think of changing it and it still closes the record without going back to enter all the data.

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

    Re: Close blank form (2002 (10.2616.2625))

    See the thread starting at <post#=301348>post 301348</post#> for a way to prevent a form from closing. <!profile=Ready4Data>Ready4Data<!/profile> posted a demo in one of the replies.

  9. #9
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close blank form (2002 (10.2616.2625))

    Still no help there...That would stop the entire database from closing....would it help to see the database so far to see my promlem?
    there are 6 text blocks for people to fill in on the form. I need the form to stay opened until all 6 are filled out... missing one is not good for what I am collecting.
    Attached Files Attached Files

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close blank form (2002 (10.2616.2625))

    Since nothing on that form is named txtField1, etc., I suspect that your problem may be copying the code without substituting appropriate control names. If the field you need to test is something like Entry1, then you have to use that fieldname in the code, not txtField1. Did you do that? If so, it isn't included in your database. Also, which 6 text "blocks" are you talking about? You have 5 Entry fields and after the update of the 5th, you open a report.
    Charlotte

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

    Re: Close blank form (2002 (10.2616.2625))

    Apart from Charlotte's comments, the form is based on a query that is not available in the database, and you haven't even tried to use the ideas from the thread I mentioned.

  12. #12
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close blank form (2002 (10.2616.2625))

    I am sorry about all the confusion. I am new to all of this and since I really don't talk to many people about it much I don't really know all the proper terms. For that I am sorry for confusing you. In the code I had changed it to look like

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.Entry_1) Then
    If MsgBox("You didn't fill in all the records. Abandon record?", vbQuestion + vbYesNo) = vbYes Then
    Me.Undo
    Else
    Cancel = True
    Me.Entry_1.SetFocus
    End If
    ElseIf IsNull(Me.Entry_2) Then
    If MsgBox("You didn't fill in all the records. Abandon record?", vbQuestion + vbYesNo) = vbYes Then
    Me.Undo
    Else
    Cancel = True
    Me.Entry_2.SetFocus
    End If
    Etc.....

    as for not including it in the database I sent a clean copy of the database so you could see more what I was talking about as when I asked questions they would make more sense to you. On the left hand of the fore is 6 text boxes (Entry 1, 2, 3, 4, 6, 5) Sorry for calling them "blocks". What is supposed to happen is that the user puts there numbers in all 6 text boxes and then a report opens up to show the graph average and range including there entries.

    I hope that this clears up some of your questions. sorry for all the confusion. I will attach the db again with all the forms/queries/reports and include the form-beforeupdate event.

  13. #13
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close blank form (2002 (10.2616.2625))

    Sorry for all the confusion. The db I sent you I had been cleared out as I thought you would only want to see just the form I was talking about. I had stripped out all the changes I had made so as to not get confused. The code I have tried so far:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.Entry_1) Then
    If MsgBox("You didn't fill in all the records. Abandon record?", vbQuestion + vbYesNo) = vbYes Then
    Me.Undo
    Else
    Cancel = True
    Me.Entry_1.SetFocus
    End If
    ElseIf IsNull(Me.Entry_2) Then
    If MsgBox("You didn't fill in all the records. Abandon record?", vbQuestion + vbYesNo) = vbYes Then
    Me.Undo
    Else
    Cancel = True
    Me.Entry_2.SetFocus
    End If
    If IsNull(Me.Entry_3) Then
    If MsgBox("You didn't fill in all the records. Abandon record?", vbQuestion + vbYesNo) = vbYes Then
    Me.Undo
    Else
    Cancel = True
    Me.Entry_3.SetFocus
    End If
    etc...

    I have also tried

    If IsNull(Me.Entry_1) Then
    Cancel = True
    Me.Entry_1.SetFocus
    End If
    etc...

    I was hoping that this might make them fill out all the records without giving then the chance to cancel the record. I know that this is not a good idea if they accidently go into this form but I wanted to try it to see if I could get it to at least do this much and work my way from there. as for the post and example from Ready4Data I tried to open it using the shift key to see the database window and design mode for the forms but it is not working for me I can't change the main form to design mode to see the code.

    I will attach a copy of the db with all the forms/queries/reports so you can better see what I am talking about. I will include the code I have last tried in the form-beforeupdate event for you to see as well. I hope that this clears up some of the confusion. I am sorry..
    Attached Files Attached Files

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

    Re: Close blank form (2002 (10.2616.2625))

    Try the attached modified version. I incorporated the ideas from the post I referred to earlier to control when the form can be closed. If the user doesn't fill in anything at all, the form is closed silently, but if some fields have been filled in and others haven't, the user must either cancel the entire record, or fill in the missing data. Take a look at the code behind the form to see how it works.
    Attached Files Attached Files

  15. #15
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close blank form (2002 (10.2616.2625))

    Thanks for the help.
    I have looked at the code modified it a little. I still have questions like what is 'dirty' but I just ordered a book so I hope that will answer some of my questions.

    thanks again

Page 1 of 2 12 LastLast

Posting Permissions

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