By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,578 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,578 IT Pros & Developers. It's quick & easy.

Adding new row using button

P: 64
Hi there,

I have a form where I want to add new row using button and done want a default new record,

I have changed "Allow Additions" to No for the forms properties
and have added following code for the button

AllowAdditions = True
DoCmd.GoToRecord , , acNewRec

Now when I click on the button and type something in newly added record (though button) it automatically creates a blank record which I dont want

I want user can only add a new record on click of a button

Any thoughts

Thanks
Jan 30 '09 #1
Share this Question
Share on Google+
7 Replies


DonRayner
Expert 100+
P: 489
You could add

Expand|Select|Wrap|Line Numbers
  1. AllowAdditions = False
  2.  
to the after update event for each of your fields.
Jan 30 '09 #2

100+
P: 675
I'd like an answer also. Adding an event to each and every control seems combursome. Perhaps using the OnDirty Event would work, but I've had difficulties when I also try to create new records in "Related" tables while creating the new record in the primary table.

OldBirdman
Jan 30 '09 #3

DonRayner
Expert 100+
P: 489
Best way to do it is not use the built in navigation control, use your own controls instead. That way you have complete control over what buttons are enabled for use at each moment.

You could then use something like the following in the on current event for the form

Expand|Select|Wrap|Line Numbers
  1.     If Me.NewRecord = True Then
  2.         Me.first.Enabled = False
  3.         Me.previous.Enabled = False
  4.         Me.next.Enabled = False
  5.         Me.last.Enabled = False
  6.         Me.search.Enabled = False
  7.         Me.add.Enabled = False
  8.      Else
  9.  
  10.         Me.last.Enabled = True
  11.         Me.search.Enabled = True
  12.         Me.add.Enabled = True
  13.         Me.first.Enabled = True
  14.  
  15.         If Me.Recordset.RecordCount < 2 Then
  16.             Me.Recordset.MoveLast
  17.             Me.Recordset.MoveFirst
  18.         End If
  19.  
  20.         If Me.CurrentRecord <> 1 Then
  21.             Me.previous.Enabled = True
  22.         Else
  23.             Me.previous.Enabled = False
  24.         End If
  25.  
  26.         If Me.Recordset.RecordCount = Me.CurrentRecord Then
  27.             Me.next.Enabled = False
  28.         Else
  29.             Me.next.Enabled = True
  30.         End If
  31.      End If
Jan 30 '09 #4

beacon
100+
P: 579
I ran into this same problem when I was creating Data Access Pages (before they basically became extinct).

The only way around it I found was to do as Don suggested and create my own navigation buttons with specific code written for the given circumstances. When it comes to the navigation buttons that are built in, there really doesn't seem to be much leeway for developers to alter their functionality.
Jan 30 '09 #5

100+
P: 675
Where is this going? Whether there are navigations on the form or not, whether they are used or not, whether they are enabled/visible or not doesn't change the original question "What should the code be for adding a new record?"
I dislike the nav buttons that Access supplies, and NEVER use them. I have my own "Add New" command button, with DoCmd.GoToRecord , , acNewRec after removing any filters for the form )I assumed that ykhamitkar did also). This presents me with a new record filled in (default) to the current record, which is not what I want. Changing the "Move First" button to Enabled = False doesn't help. As a matter-of-fact, moving to the first record strongly implies that I am finished with the Add-New.

OldBirdman
Jan 30 '09 #6

DonRayner
Expert 100+
P: 489
OldBirdman;

The problem that the origional poster is having is. When in datasheet view and running his code, as soon as he starts typing into the new record access is creating another blank record for data entry directly below the one he is typing in.

Thus the origional poster is looking for a way to not have that blank record available to his users to enter an additional record without clicking on his button.

While AllowAdditions is true, access will always create this blank record when the current blank record has anything added to it. He will have to change AllowAdditions to false before his users get a chance to enter any additional records.

Thus using the AllowAdditions = False in the afterupdate event for the fields will accomplish what he wants. Your suggestion on using the OnDirty event will probally work as well.

As for your problem with the addnew command, I'm not quite sure what the problem that you are having is. In a Form/Subform combination the fields that are linked in a Child/Parent relationship between the two will always be filled in on the subform. It couldn't work any other way and still keep the relationships intact. Could you post back with some more information or examples?
Feb 2 '09 #7

100+
P: 675
Thanks for the explanation. I had missed the DataSheet view in the initial problem. My problem is somewhat different, and I'll post in a new thread when I can isolate it from a project too complex to discuss here.

OldBirdman
Feb 2 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.