
Letting Access Form Add New Record
Gary,
Just a small point of information for you. The "acSaveYes" option of the
close command saves any _design_ changes that may have been made to the
object you are closing, not changes to the records that the form is
accessing. Edits to the current record are saved automatically by Access
when you close a form or move to a new record.
Also, you need to specify what type of object you are closing, so the
command should read
DoCmd.Close acForm, "Name of Form"
--
Jon Ley
Reply address is anti-spammed.
Please reply to the newsgroup for the benefit of others,
and to encourage further discussion.
Quote:
>David,
>The record can be saved all at one time. I am guessing this is a data entry
>form.
>Try the following:
>1. Place the customer_number text box on the form and set its visible
>property to no.
>2. Place a command button on the form, label it Save and Exit, name it
>cmdSave.
>In the buttons on click event use the following.
>Sub cmdSave_Click()
>If IsNull(Me!NameOfPhoneField) Then
> MsgBox "You must enter the phone number"
> Me!NameOfPhoneField.setfocus
> Exit Sub
>End If
>Me!customer_number = Me!NameOfPhoneField (Of whatever code you use to
modify
>the primary phone number into the customer number.
>DoCmd.Close "Name of Form", acSaveYes
>End Sub
>Hope this helps,
>Gary Wunrow
>> Hello,
>> I have a form in Access 2000 that is based on my customer table. I
>> have also removed all the record navigation buttons. I would like to
>> have the form take care of saving all the filled in fields with the
>> exception of one. The exception is the "customer_number" field, which
>> is based upon the customer's primary phone #. I would like to manually
>> (through VBA code) save the "customer_number" and then have the form
>> save all the fields that are bound to the form. Here is the code I am
>> using.
>> Sub SaveRecord
>> Me.Recordset.Edit
>> Me.Recordset("customer_no") = lblCustomerID.Caption
>> Me.Recordset.Update
>> DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord
>> End Sub
>> When I try this code I get the following error.
>> "This action was cancelled by an associated object"
>> Does anyone have an idea as to what I might be doing wrong? Thanks for
>> any suggestions.
>> Sent via Deja.com http://www.deja.com/
>> Before you buy.