Results 1 to 5 of 5
  1. #1
    hmushtaq is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2010
    Posts
    10

    Resetting a form having "Required" fields

    Hi!
    I have a form which has 4 fields set as "Required". When I try to dirty the form and then try to reset it using a button, it does clear all the fields, but when I try to close the form, it gives me the error that the "xyz" field is required. I want to keep those fields set as required, but yet would like to have a reset button that can clear the fields for the user if they have made a mistake during data entry.

    Second problem is that on the same form, I have a subform. The Reset button is in the header section of the main form. By clicking this button, I would also like the subform to be reset. The reset button includes code for the subform to reset, but it also has the same problem error. There are required fields on it. How can I reset a form and provide the primary key fields and the required key fields Null values when they can't have Null values?

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    if your key fields are autonumber - and they've generated a value - then a record has been created. So that's a done deal. You can't undirty your way out of it at that point.......b.t.w. There is no such thing as 'reset' in db parlance..... So you would need to delete that record, and then I guess start a new record....that will affectively give the user a reset experience.....

    If the autonumber is not generated...then you can undirty out of it - but it sounds like that's what you are now trying that isn't working....

    Hope this helps.

  3. #3
    hmushtaq is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2010
    Posts
    10
    Thanks NTC for your reply. I appreciate your time.

    You are definitely right about whatever you have mentioned. I have managed to code things in the form_BeforeUpdate event to not let un-validated data to be saved. This is done on both the Main form and the subform. I have also managed to reset the fields on both the forms. But there is a problem.

    First, if the user enters data on the main form and decides to cancel it, the form doesn't get closed, because now it requires the primary key field and all required fields to be filled. How to get rid of this thing and make sure that the user can cancel and close the form?

    Second, if the user does continue entering in the main form, and then enter the subform, and then decides to cancel the form, the data through the main form would have already been saved, and if the user tries to close the form, the subform required fields and primary key fields will not leave the user without first entering the data.

    You mentioned about deleting the record, but the question of deleting the record arises only after the record has been completely saved. if the user decides to cancel the entry in the middle, how do I make sure that the record still gets saved, even though the user has missed the required fields? if somehow I can do this, then yes I can delete the record.

    Also can we turn off these required key or duplication warning messages? I tried DoCmd.SetWarnings False, but doesn't work for these messages. Your help will be highly appreciated. TIA

  4. #4
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    I think the only answer is best done in general fundamentals - as forms can have alot of issues and also table field properties such as autonumber & default values can affect the issue. Very tough in a forum to fully describe a complex form...

    ps. you might turn on the 'Record Selector' property of the form at least temporarily if it is off ...because there you get a visual prompt of dirty...you will see the icon change to the pencil... and this maybe help.

    But I've had your same situation; and one must step thru every iteration of what the user might do - - and when they might bail out - - - and note along the way whether the record is written yet - or still new and just dirty.....and then you have tools of dirty property, before update, deletequery, etc to deal with each user action scenario....

    If you have a specific question about a method to implement that can be answered but I think really so far your issue is architecting the design....and that's why they pay you the big bucks!

  5. #5
    hmushtaq is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2010
    Posts
    10
    Thank you for your help NTC.

    I was already implementing the suggestions you gave me. Anyways I have found my solution. Only one statement and it replaced many lines of code.

    Me.Undo

    This resets all of my form, and without giving me any warnings if I close the form after resetting the fields. Even the subform is working fine.

    I appreciate your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM
  2. Replies: 5
    Last Post: 08-10-2010, 02:57 PM
  3. Replies: 4
    Last Post: 06-14-2010, 02:31 PM
  4. Fields do not show in "Form View"
    By hawzmolly in forum Forms
    Replies: 4
    Last Post: 01-09-2010, 06:27 PM
  5. Link tables on "special" fields
    By Gargen in forum Access
    Replies: 0
    Last Post: 12-18-2008, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums