Solved

Create new record in a form based on data entered in an unbound form

Posted on 2006-07-06
20
306 Views
Last Modified: 2010-05-18
We have an unbound form called frmNewPolicy containing the following fields:
ContactID  (a combo box)
ProviderID (a combo box)
ProductID (a combo box)
FundID (a combo box)
KFDRef (a text box)

Also on the form is a control button which opens the form frmPolicy (which has a subform called subPolicyFund - linked by PolicyID

On opening that form it should
1) Go to a new record (creating a new PolicyID)
2) Put the ContactID from frmNewPolicy in to the ContactID combo box in frmPolicy
3) Put the ProviderID from frmNewPolicy into the ProviderID combo box in frm Policy
4) Put the ProductID from frmNewPolicy into the ProductID combo box in frmPolicy
5) Put the FundID from frmNewPolicy into OriginalFundID combo box in the SUBFORM subPolicyFund
6) Put the KFDRef from frmNewPolicy into the KFDRef text field in frmPolicy



0
Comment
Question by:Ludique
  • 12
  • 7
20 Comments
 
LVL 84
ID: 17050713
Your code in the button would be like this:

DoCmd.OpenForm "frmPolicy", , , , acFormAdd
Forms("frmPolicy").ContactID = Me.ContactID
Forms("frmPolicy").ProviderID= Me.ProviderID
etc etc
Forms("frmPolicy").subPolicyFund.Form.OriginalFundID= Me.FundID

Of course, your combos will have to be setup properly in frmPolicy with the correct .RowSources
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17050721
do something like this on form load:
docmd.GoToRecord , , acNewRec
me.contactID = forms!frmNewPolicy!ContactID
'repeat for other comboboxes
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17050753
for the subform one you can do something like:

me.subformname.controls("OriginalfundID") = forms!frmNewPolicy!FundID
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17050815
one issue with putting all of this in the on load of the form is that you might want to open frmPolicy without opening it via frmNewPolicy, if that is the case, then do something like this:

frmNewPolicy's button to open frmPolicy

onclick:
DoCmd.OpenForm "frmPolicy", , , , , , "frmNewPolicy"

that will pass "frmNewPolicy" to frmPolicy when it opens, so you can do this:

frmPolicy's onload:
if me.openArgs = "frmNewPolicy" then
   docmd.GoToRecord , , acNewRec
   me.contactID = forms!frmNewPolicy!ContactID
   me.providerID = forms!frmNewPolicy!ProviderID
   me.productID = forms!frmNewPolicy!ProductID
   me.KFDRef = forms!frmNewPolicy!KFDRef
   me.subpolicyfund.controls("OriginalfundID") = forms!frmNewPolicy!FundID
end if

not sure exactly what your control names are, so you may need to change that
0
 

Author Comment

by:Ludique
ID: 17050857
Thank you thank you thank you
We're trying out options now - back with points in a bit!
thank you thank you thank you
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17050954
your welcome your welcome your welcome
either solution will work, LSM's will do all the work in frmNewPolicy, mine will do all of the work in frmPolicy
your welcome your welcom your welcome :) :)
0
 

Author Comment

by:Ludique
ID: 17051079
Good so far..... the code looks like this:

Private Sub Form_Load()
If Me.OpenArgs = "frmNewPolicy" Then
  DoCmd.GoToRecord , , acNewRec
  Me.ContactID = Forms!frmNewPolicy!ContactID
  Me.ProviderID = Forms!frmNewPolicy!ProviderID
  Me.ProductID = Forms!frmNewPolicy!ProductID
  Me.Kfdreference = Forms!frmNewPolicy!Kfdreference
  Me.subPolicyFund.Controls("OriginalFundID") = Forms!frmNewPolicy!FundID
End If
 
End Sub

BUT..........
the PolicyID (autonumber) which is created when the new record is created in frmPolicy does not get refreshed/updated in subPolicyFund

If we refresh the form subPolicyFund manually the PolicyID is put into the field but
we'd like it to happen automatically
We've tried putting
me.Refresh into the OnLoad of frmPolicy and subPolicyFund
but it didn't work

Could we put a refresh command into the code above
or should it be on another control on frmPolicy
or on subPolicyFund?
0
 
LVL 6

Accepted Solution

by:
yhwhlivesinme earned 500 total points
ID: 17051105
Private Sub Form_Load()
If Me.OpenArgs = "frmNewPolicy" Then
  DoCmd.GoToRecord , , acNewRec
  Me.ContactID = Forms!frmNewPolicy!ContactID
  Me.ProviderID = Forms!frmNewPolicy!ProviderID
  Me.ProductID = Forms!frmNewPolicy!ProductID
  Me.Kfdreference = Forms!frmNewPolicy!Kfdreference
  Me.subPolicyFund.Controls("OriginalFundID") = Forms!frmNewPolicy!FundID
  Me.subpolicyfund.refresh '<---try this
End If
End Sub
0
 

Author Comment

by:Ludique
ID: 17051118
We get a compile error "Method or data member not found"
and it highlights
.refresh
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17051196
anyway you could upload a copy of your database to www.ee-stuff.com ?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17051215
in the meantime you could also try:

me.subpolicyfund.Requery
0
 

Author Comment

by:Ludique
ID: 17051335
: (

Still works if you refresh subPolicyFund manually but doesn't work otherwise.

What's the difference between requery and refresh?
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17051380
requery actually runs the backend query again and refreshes the recordset, refresh just refreshes the screen....
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17051403
try moving all the on_load code to the on_open event, see if that makes a difference
0
 

Author Comment

by:Ludique
ID: 17051610
We think you're lovely.
But it still doesn't work.
0
 

Author Comment

by:Ludique
ID: 17051652
We think you're lovely.
But it still doesn't work.
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17051682
haha, any chance of getting the database uploaded? you could remove all the data if confidentiality is an issue....

either way let me make sure that I'm understanding you correctly,

you have a textbox on the main form that has PolicyID (autonumber) as it's controlsource.  you also have another textbox in your subform that has PolicyID as it's controlsource.  After the code is executed the policyID in the subform has not been updated with the same number in the parent form. those PolicyID's are in the same table correct?
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17051684
thanks for the points, do you have it working?
0
 

Author Comment

by:Ludique
ID: 17052290
No - it's gone very very wrong
getting the usual run of database is corrupt messages eg
error loading dll
id not an index on this table
invalid argument
etc

Just going to recover everything - this could take a while.
0
 
LVL 6

Expert Comment

by:yhwhlivesinme
ID: 17052302
oh geez! your problem might be something deeper than just the coding behind the form
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now