PC Review


Reply
Thread Tools Rate Thread

adding a new record at subform should update an existing record (not create new record)

 
 
Mark Kubicki
Guest
Posts: n/a
 
      15th Jan 2009
I have 2 tables that are related:
- tblManufacturer contains,among other things, a list of manufacturers
[strMfr] and the name of the agency that reps them [strRepAgency]; there
is only 1 of each manufacturer, and each manufacturer has only 1 rep
- tblRepAgencies contains detailed information about the RepAgency; each
RepAgency can represent many manufacturers

I have 2 forms:
- frmManufacturers is a continuous form with a text box: txtMfrm and a
combo: cboRepAgency (with a row source of tblRepAgencies); Manufactures'
names [strMfr] are entered in this form, and a rep agency [strRepAgency] can
be chosen for manufacturer
- frmRepAgencies is a single form where the RepAgencies are entered; it also
contains a continuous subform [subRepAgencies_MfrList] where manufacturers
that the agency represents can be entered / viewed

The problem I have is:
- When I add a new manufacturer to the frmRepAgencies subform
[subRepAgencies_MfrList], it creates a new record in tblManufacturer. This
causes a manufacturer to have multiple entries
- What I want it to do is update the manufacture's rep info on the existing
record (not create a duplicate entry for the same manufacturer.)

Any suggestions would be greatly appreciated...
thanks in advance,
mark


 
Reply With Quote
 
 
 
 
strive4peace
Guest
Posts: n/a
 
      16th Jan 2009
Hi Mark,

how about making AllowAdditions to subRepAgencies_MfrList = false?

use a listbox on the main form to show manufacturers that are not
currently using the rep shown in the main form

when a user selects a manufacturer from the listbox, use an update query
to set the rep, then requery the subRepAgencies_MfrList subform

on the AfterUpdate event of the listbox:
'~~~~~~~~~~~~~~~~~~~~~~~~~~
if isNull(me.listbox_controlname) then exit sub

dim strSQL as string

'change rep in manufacturer record
strSQL = " UPDATE tblManufacturer " _
& " SET strRepAgency = '" & me.RepAgency_controlname & "'" _
& " WHERE strMfr = '" & me.listbox_controlname & "'"
currentdb.execute strSQL

'clear listbox
me.listbox_controlname = null

'show manufacturer on the subform
me.subform_controlname.requery
'~~~~~~~~~~~~~~~~~~~~~~~~~~

you might want to first check to see what rep is listed for that
manufacturer -- and ask the user if they are sure they want to replace
it. If no rep is listed, don't even bother asking... and give a way to
delete a rep from the manufacturer record as well.

Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




Mark Kubicki wrote:
> I have 2 tables that are related:
> - tblManufacturer contains,among other things, a list of manufacturers
> [strMfr] and the name of the agency that reps them [strRepAgency]; there
> is only 1 of each manufacturer, and each manufacturer has only 1 rep
> - tblRepAgencies contains detailed information about the RepAgency; each
> RepAgency can represent many manufacturers
>
> I have 2 forms:
> - frmManufacturers is a continuous form with a text box: txtMfrm and a
> combo: cboRepAgency (with a row source of tblRepAgencies); Manufactures'
> names [strMfr] are entered in this form, and a rep agency [strRepAgency] can
> be chosen for manufacturer
> - frmRepAgencies is a single form where the RepAgencies are entered; it also
> contains a continuous subform [subRepAgencies_MfrList] where manufacturers
> that the agency represents can be entered / viewed
>
> The problem I have is:
> - When I add a new manufacturer to the frmRepAgencies subform
> [subRepAgencies_MfrList], it creates a new record in tblManufacturer. This
> causes a manufacturer to have multiple entries
> - What I want it to do is update the manufacture's rep info on the existing
> record (not create a duplicate entry for the same manufacturer.)
>
> Any suggestions would be greatly appreciated...
> thanks in advance,
> mark
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create new record using a form based on an existing record =?Utf-8?B?QWxleA==?= Microsoft Access Forms 2 4th Nov 2004 02:28 PM
Re: Update existing Record and create new record Larry Linson Microsoft Access 1 5th Jul 2004 06:46 AM
How does one protect against subform adding record before main form has record? Chips Microsoft Access Forms 3 2nd May 2004 04:19 PM
form / subform - problem adding new record! - can't save main record Bob Microsoft Access Forms 2 7th Oct 2003 06:19 PM
Stop adding record in subform after record count = 1 Charlie Microsoft Access Forms 0 31st Jul 2003 11:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:04 AM.