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

Open a Form without running a sub-form 2

Status
Not open for further replies.

Cabrita

Technical User
Apr 3, 2002
140
PT
Hi,

My question is how can I define in code that source object of a sub-form, so that the data for that sub-form would only run when I define it.

Best Regards and happy new year.

Andre
 
I have tryed like this:

Me.nameform.SourceObject "query name"

But I get this error message: Invalid use of property

Any ideas?

Thank you
Andre
 
Hi Andre!
Try this:
1) put the code in the Activate() event of the parent form
2)change it to:
Code:
 me.yoursubform.sourceobject[b]=[/b]"query name"

Hope this does it.

Greetings,
Andy


Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
Hi Andreas,

Thanks for your help, I get a compile error... But my knowledge in VB is very limited so I don't know what you want me to do in the first point.

Thanks
 

Sorry Andre - Hmpfff [rofl3] my mistake!
I had only half-read your post.
What you need to change is the record source, not the source object:

Put this in
Code:
Sub Form_Open()
If DCount("[ID]", "your query name")>=1 Then
  Me.RecordSource="your query name"
End If
End Sub

Whereas [ID] is one field from your query (it can also be [RecID], [FirstName] or whatever fields you have...

Didn't mean to confuse you... [afro2]
 
Hi Andreas,

Thank you so much!!

Happy new year !!

Andre
 
Sorry, but I has a problem with your solution. I have a botton on the principal form when clicked I want to make the sub-form to run, and your solution only works if that botton is inside the sub-form. Do you have any solution?

Thank you very much

Andre
 
hi, I have a similar form set up. I set the subforms visible property setting to false, and then in the event procedure on the button I use to trigger the subform I have this:


Private Sub ComPushMe_Click()
Me![subformInQuestion].Requery
subformInQestion.Visible = True

End Sub



Hope that helps. :)


Michael
 
Hi Michael,

That's a solution, but it does not solve my problem, because the form still runs but it's not visible. What I need is for the sub-form only runs when I press the botton, because it takes time for the sub-form to load...

Any ideas? Thank you

Happy new year!

Andre
 
Hi Andre!

You could try combining mine and Michael's approach:
- Set the default visibility of the subform to FALSE.
- Replace
Me.RecordSource="your query name"
with
Me.YourSubform.RecordSource="Your Query"
Me.YourSubform.Visible=True

So the code of your button on the main form would be like this:
Code:
Sub yourbutton_click()
If DCount("[ID]", "your query name")>=1 Then
  Me.YourSubform.RecordSource="Your Query"
  Me.YourSubform.Visible=True
  me.Repaint
End If
End Sub

Hope this helps,
Andy


Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top