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
303 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

930 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

11 Experts available now in Live!

Get 1:1 Help Now