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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help setting subform control default values from main form 1

Status
Not open for further replies.

cwadams1955

Programmer
Jan 21, 2008
52
CA
Hi, I'm working on a main form which will contain five embedded subforms (same form, just using different queries to return different subsets of data.) On these subforms, I need to set the default value (ideally in the OnOpen event of the mainform) to the value contained in a bound text box on the main form. Example: main form contains bound text box ProjectNo. When the form opens, I need to set the default value of a bound text box called ProjectNo on each of the subforms.

I can set the subforms' data source property with no problem; it queries the recordset perfectly and returns the correct data. But no matter what method I've used to try setting the default value of one of the controls on a subform, I get a runtime Error 438 (Object doesn't support this property or method .)

Here's the code I have right now:

Code:
Me![Child1].Form![ProjectNo].DefaultValue = "'" & Me![ProjectNo].Value & "'"

where [Child1] is the name of the subform control on the main form. I've put this in the OnCurrent and the OnOpen event, and it throws the same error either place.

Searching has turned up several instances of this exact code offered as a solution to this type of scenario, but it's not working for me. Any ideas? Thanks for any assistance.
 
Have you tried the same event or control that changes the query?

It is possible to sent the default value to:

[Parent].[ProjectNo]
 
Yes. The query gets changed during the OnOpen event of the main form. That code looks like this:

Code:
    strSQL = "SELECT * FROM tblBillRecordDetail " & _
            "WHERE [ProjectNo]='" & Me.ProjectNo & _
            "' AND [TaskNo]='" & Me.TaskNo & _
            "' AND [WEDate]='" & Me.WEDate & _
            "' AND [ServiceArea]='DRL' " & _
            "AND [ServiceCode]='SDS'"
    
    Me.Child1.Form.RecordSource = strSQL

And this works fine. But I can't even set a breakpoint here and use the immediate window to print the default value of the subform's ProjectNo field - I get the same error.

I'll try going the opposite route like your example and see if it will let me refer to the parent form controls from within the subform.
 
I mean that there is no need to use code to set the default value, the property itself can be set as illustrated.
 
Yeah, that's what I was going to do. And then I found a mis-typed field name, which I corrected and now my original code works. Gah. I'm not sure why I wasn't getting other errors, probably because there really isn't a lot going on in this form (yet.) Anyway, thanks. Next time I'll just plug in the reference like you have there...
 
Anyway, as you reference controls, I'd use the Load event instead of the Open.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top