Letting Access Form Add New Record 
Author Message
 Letting Access Form Add New Record

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 customers 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.*-*-*.com/
Before you buy.



Mon, 23 Dec 2002 03:00:00 GMT  
 Letting Access Form Add New Record
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

Quote:

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



Mon, 23 Dec 2002 03:00:00 GMT  
 Letting Access Form Add New Record
All you need to do is use the BeforeUpdate event to fill in the
customer_no based on the phone number. Something like:
If isnull(me.customer_no) then me.customer_no = me.phone

Then anytime the form is saved or even closed, this will take care of
itself. Your button would just need to do a save.

 -- Andy

Quote:

>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 customers 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.



Mon, 23 Dec 2002 03:00:00 GMT  
 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.



Tue, 24 Dec 2002 03:00:00 GMT  
 Letting Access Form Add New Record
Thanks for the correction Jon. You are absolutely correct.

Gary Wunrow

Quote:
> 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.


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



Tue, 24 Dec 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Letting Access Form Add New Record

2. word VBA won't let me add a new record to an access table

3. adding new records and accessing records from form code

4. Access wont let any users add records

5. Access 2000 Crashes Adding New Record From Form on Some machines

6. #Deleted displays on Access form after adding new record

7. Adding a new record by popping up a new form

8. Combo,NotInList, adds new data BUT advances form to new record

9. Adding a new record to a form whose record source is a listbox

10. Adding a new record by copying record already on the form


 
Powered by phpBB® Forum Software © phpBB Group