Solved

How to hide the new record fields in a form except when I want to add a new record

Posted on 2004-08-16
5
320 Views
Last Modified: 2008-01-09
There is always a blank new record at the bottom of a continuos form waiting for new data to be enetered.  This can be not shown by saying no to allow additions in the properties box.

How can I switch between allow additions and not allow additions so that in normal viewing the blank fields are not seen but when a button is clicked to add a new record then the form is switched to allow aditions
0
Comment
Question by:jimcrint
5 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 11817610
What are you using DBGrid??
0
 
LVL 3

Expert Comment

by:Sajjaninj
ID: 11817789
too much little info.. what are the controls,dao or ADO... etc.
0
 
LVL 1

Author Comment

by:jimcrint
ID: 11817846
Sorry I was not thinking that other people would be able to read my mind

I am using Access 2000.  I have created forms and normally have a button to add a new record then take control to the first field.

This client does not want to see the empty new record so I thought I could turn on and off the "allow additions" that is available in the properties,

This may be to simplistic and I need to create the new record in the table then refresh the form to show it.  Not quite sure here.
0
 
LVL 5

Accepted Solution

by:
jmacmicking earned 250 total points
ID: 11819537
Set the form's AllowAdditions (under the Data tab) property to false.  This will turn off the blank record at the end of the list.

In the code for the button put the lines
  Me.AllowAdditions = True
  DoCmd.GoToRecord , , acNewRec

This will turn additions back on and move the highlight to the new record.  However, once they start typing the form will create another empty record.  There are two ways to avoid this (that I can think of)--one is to change one or more of the values on the new record in code right after it's created then set Me.AllowAdditions back to False.  Since the new record is dirty it won't disappear when AllowAdditions is turned off.  The other method is to set the OnChange event of each control to turn off AllowAdditions if it's on.  Personally, I'd just set one of the values to a default with this code (put it in the button's Click event):

  Me.AllowAdditions = True
  DoCmd.GoToRecord , , acNewRec
  Me.RowName = ""
  Me.AllowAdditions = False

Two other options that may work, even if they aren't quite what you asked for:
    Don't allow additions on the list form at all; when the button is clicked open a seperate form designed for data entry (set it's DataEntry property to true so it only shows new records).  On the close event of the new form force the continous form to requery (to capture the new data).
    Put all the controls necessary for a new record in the form footer, put a "Add Record" and "Cancel" button as well.  Mark them all as Visible=False initially.  When the Add button is clicked show the controls.  If the person clicks Add Record add the record programatically and then requery the form.  If they click Cancel just set all the controls back to default values (blank, probably) and set thier visible property back to False.

Personally, I'm a fan of seperate forms for data entry.  It's much easier to validate the data and it's often clearer to fill out.  If you need more detail on any of these methods or have any questions let me know.
0
 
LVL 1

Author Comment

by:jimcrint
ID: 11825942
Excellent, just what i wanted

I had already done one of your other options for a separate form to input data into but there are about 6 of these in sub forms and tabs so it would be come rather messy for me.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question