linking forms and adding a record

G

Guest

I am entering data into to forms.

I have a Master_Jobs form I have an Account_No field and a drop down list
for the Job_type field where when I select a particular job type, in this
instance it would be "New Contract" a form with Contract Type Option box.
There are 3 options on this form, and when one is selected, in this case,
"BPV Contract", the BPV Contract form opens in add record mode.

From the Master_Jobs form, I would like the Master_Jobs!Account_No to appear
in the Frm_BPV_Contract!Account_No field.

Can anyone give me clue as to how I can accomplish this?

I have tried creating a variable named Current_Contract_No and saving the
value from Master_Jobs!Account_No

as follows:


Current_AccountNo = Master_Jobs!Account_No.value


But Current_Contract_No is coming up empty when I try to put the value into
Frm_BPV_Contract!CDBPV_Account_No as follows


Private Sub Frame_Contract_Type_Option_AfterUpdate()

Select Case Me!Frame_Contract_Type_Option

Case 1

DoCmd.OpenForm "frm_contract_data_BPV", , , , acFormAdd
If Not IsNull(current_AccountNo) Then
CDBPV_Account_No = current_AccountNo
End If

Case 2 . . .


Is this the wrong place to do this?

Any help would be appreciated.

Thank you,

Emma
 
M

MtnView

Hello,

If I understand your question, the field can be passed to the form in
the OpenArgs parameter like:

DoCmd.OpenForm "frm_contract_data_BPV", , , ,
acFormAdd,,Current_AccountNo

Then in your frm_contract_data, use the Form's OnOpen or OnLoad event
to retrieve the data like this:

Me!CDBPV_Account_No = Me.OpenArgs
 
G

Guest

Would this also work if the form being opened from frm_tbl_Master_Jobs is not
the form where I need Account_No? I am opening a frm_Contract_Option before
I open the frm_contract_data_BPV and frm_contract_data_BPV is where I need
the Account_no field from tbl_Master_Jobs.

I guess what I am asking is, does the OpenArgs parameter keep the value
until I clear it?
 
M

MtnView

Hello,

The OpenArgs parameter passes data only to the form that it opens in
the DoCmd.OpenForm statement. If one form opens the next, you could
pass it along again.

Or, you might try using a Public variable in a module (from the
database window). It's not highly recommended in structured
programming, but it works. These Public variables normally can be
accessed from code in any form. If you use this method, try to identify
them clearly, so they will not get confused with variables in form
modules. I usually name them something like GlobalVarCurrent_AccountNo.

You could also create a table for GlobalVariables on the front-end of
your database.
 

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

Similar Threads


Top