Can't create new record in subform

D

dee

I have a main form "FmLeads".
It contains a field "Salesman" which has an 'After Change' Event
Procedure.

The Main form "FmLeads", contains a subform "FmDispoHistory". It
displays all historic Salesman changes in continuous form format.

It is related to with ONE "FmLeads" record -->> MANY "FmDispoHistory"
records via an ID field.

I need the Salesman 'After Change' Event Procedure on the main form to
add a new record to the "FmDispoHistory" subform, and then to assign
the value of the "Salesman" field from the main form to the "Salesman"
field in the subform.

Could someone help me with a few lines of VB code that can do tjhis?
Thank You
 
A

Al Campagna

Dee,
First, you'll need to use the AfterUpdate event of Salesman to trigger the code, not
the OnChange event.
The OnChange event fires every time you enter a character in a control. So, entering
"Smith" would cause the code to fire 5 times.
The AfterUdate event fires only once when entry in a control is complete.

You wrote...
I need the Salesman 'After Change' Event Procedure on the main form to
add a new record to the "FmDispoHistory" subform.

Do you have your subform property AddNew set to NO? If not, then a new record already
exists in the subform, after the last entered record, waiting for data entry.
This code assumes you have not set the AddNew property to NO...

Private Sub Salesman_AfterUpdate()
Forms!FMLeads!FmDispoHistory.SetFocus
DoCmd.GoToRecord , , acNewRec
Me.FmDispoHistory.Form!Salesman = Forms!FMLeads!Salesman

That should do it if all your setup is as you described...

But... I'm a bit concerened about you're changing the main form from Salesman to
Salesman each time there the need for another subform record.
It would seem that each Salesman should have their own main form record, (in the ONE
table) and that the subform would only list entries against that particular Salesman. (in
the MANY table).
Your description of your setup makes me think there "may" be a table/form design
problem.

Regardless though... the above code should do the job

--
hth
Al Campagna
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
A

Al Campagna

dee,
Please don't post the same question to "individual" newsgroups. People who respond in
one group don't realize that others are responding in another, thus duplication of effort
and lack of "continuity" in the problem determination process.
Occaisional "multi-posts" are OK, but combine the newsgroups in the TO section of one
post
ex.
Newsgroups : microsoft.public.access.formscoding ; microsoft.public.access ;
microsoft.public.access.forms

Then, anyone's response in one group is seen by all the newsgroups.

Thanks,
--
Al Campagna
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top