Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default value in Subform 1

Status
Not open for further replies.

yummy7

Technical User
Jun 2, 2006
195
0
0
CA
I have a main form and subfrom in it. When I go for new record in subform, enter data in subform, I also have to put value of Device_ID which i already selected from comboBox in mainform. So I want Device_ID feild in subform should have the default value,no need to write.The following code works fine. But I dont know whts the right event to put in.

Device_ID.DefaultValue = Me.Parent!Combo269.Column(1)

Any suggestion is most appreciated.
 
Have you looked at Link Child and Link Master fields? If you set these for the subform control, Access will automatically fill the Link Master field (main form) into the Link Child field (subform).
 
I know it,but the problem is the foreign key in subform is SrNo which is PK in main form. So it is already giving me all the devices of related stores.Now i filter devices through combo in main form. When i filter, it filters fine giving Device_ID,Device type etc from table.
The problem is when i go for new record in subform. I have to enter Device_ID,although i selected it from combo but still have to enter manually.
I put the above code in the click event of Device_Type,works fine but this is not good practice as user can click any feild of subform. I tried (on load,Active,got focus events) but of no use.
help me:(
 
You can set the default value for the subform field in the After Update event of the combo.

It is possible to have more than one link field.
 
i pchanged this code and put in the after update event of combo. But its not working and i know its Syntax is not right.
Me![Device_Details subform].[Device_ID].Form.DefaultValue = Me.Combo269.Column(1)
Please tell me the right one.
 
You need:
[tt]Me.[Device_Details subform].Form.Device_ID.DefaultValue=Me.Combo269.Column(1)[/tt]

Combo box columns start numbering at zero. I suspect you do not need a reference to the Column property. Consider renaming your combo to something meaningful, you will be glad you did later.
 
Its giving error "Microsoft cannot find feild '|' reffered to in your expression".Here is the code:

Private Sub Combo269_AfterUpdate()
Me.Child281.Form.Filter = "Device_Type = '" & Combo269.Value & "'"
Me.Child281.Form.FilterOn = True
Me.Child281.Visible = True
Me.[Device_Details subform].Form.Device_ID.DefaultValue = Me.Combo269.Column(1)
End Sub
Combo has two columns(Device Name,Device ID)so i need Device_ID.
 
Your subform control is not called Device_Details subform, it is called Child281. It is important to distinguish between the name of the subform control and the name of the form contained. While they are usually the same, in this case they are not. Try:
[tt]Me.Child281.Form.Device_ID.DefaultValue = Me.Combo269.Column(1)[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top