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
294 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
Comment Utility
What are you using DBGrid??
0
 
LVL 3

Expert Comment

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

Author Comment

by:jimcrint
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now