views:

85

answers:

3

So I recently have been trying to incorporate more sub forms to make the UI more friendly. So I have a pre developed form that runs some VB, so for examples sake lets just say that it runs SQL statement, returns the recordset, and fills text boxes with the data (because this is sort of an interactive dashboard concept:

dim db as database
dim rs as recordset
dim sql as string
set db = current db

sql = "SELECT * FROM tblMain;"

   set rs = db.OpenRecordSet(sql)

         rs.movefirst
             [forms]![DashboardSubName].txtValue1 = rs!Value1
         rs.close

 set rs = nothing
 set db = nothing

with error handling that returns a error "DashboardSubName" not found. So orginally this form was its own form, and opening it by itself it works fine, but once I use it within the parent form i get this error.

im sure it is simply something i am not aware of, but what gives?

thanks guys justin

+3  A: 

When a Form is loaded as a sub-form, it is referenced as if it were just another control on the Main Form - it is no longer part of the global Forms collection.

So the correct reference should be: Me!DashboardSubName.Form.txtValue1

where DashboardSubName is the name of your sub-form control.

MrUpsideDown
More info: http://www.mvps.org/access/forms/frm0031.htm
Remou
thanks guys for the information! it helps!
Justin
+1  A: 

Assuming the code you showed us is part of the subform, rather than the parent form, replace

[forms]![DashboardSubName].txtValue1 = rs!Value1

with

Me.txtValue1 = rs!Value1
HansUp
thanks Hans....that is what i was getting at and it is all working now.
Justin
+1  A: 

The reason for the syntax here is that the subform control is distinct from the subform embedded inside it. The subform control has properties of its own (limited in comparison to the subform itself), and to get to the properties/methods of the subform embedded in it you have to specify that you want the form that the subform embeds.

  Me!MySubformControl

...is the subform control.

  Me!MySubformControl.Form

...is the form embedded in the subform control.

Last of all, I really wonder why you're walking a recordset to update data in a subform. This is not normal practice, though it's tangential to your actual question.

David-W-Fenton
thanks David. To answer your question, I had a whole lot of forms for one user type that acted as dashboards, with a bunch fo drill down. the drill down need to have functionality to select individual results, and build the sql statement based on a series of selections. I just started to convert to subform, to make the overall UI a little friendlier. I would not be surprised if it is not the best way to handle it....just the way i figured out how to get it done. I am always open for learning better EASIER ways. thanks
Justin
I'm not understanding what you're saying. It sounds like you're viewing data, not updating. And, of course, the word "dashboard" is completely opaque to me -- I haven't a clue what you are referring to with the term.
David-W-Fenton