?
Solved

subform is processing before parent form finishes loading (ADP)

Posted on 2004-09-13
10
Medium Priority
?
497 Views
Last Modified: 2008-02-01
This particular quirk hasn't happened to me before.  I have a form that has a subform.  The subform's record source is a stored procedure and there are two input parameters.  There are no child/master links between the two forms, but the parameters for the subform are pulled from the main form.  The Input parameters line looks like this:

@Date smalldatetime = [Forms]![frmOrders]![tbxDate], @Crop nvarchar(25) = [Forms]![frmOrders]![tbxCurrentCropID]

The problem is that when I open the parent form, popups that ask for parameter inputs are appearing.  I was thinking that this was happening because the subform was trying to process the stored procedure before the form loaded.  So I make sure in my form's Load event that the two fields that control the parameters are set to something (the current date and the first crop of a drop down list).  Then I put in a couple test msgbox popups to show me these values.  

Well, the parameters popups are still popping up BEFORE my msgbox popups (which have the correct values), indicating to me that the subform is trying to process the data even before the Form_Load event?  I don't understand. I have other forms/subforms with this setup, and those are working fine so there must be some detail I am overlooking...

Thanks for any help.
0
Comment
Question by:rsoble
  • 6
  • 4
10 Comments
 
LVL 39

Expert Comment

by:stevbe
ID: 12045562
subforms do load before the parent ... try using code to set the subform's recordsource in the parent's Load event.

Steve
0
 
LVL 1

Author Comment

by:rsoble
ID: 12056333
Thanks Steve.  I did what you said and progress is being made.  However I think I have the syntax wrong for the InputParameters line below:
-----------
Private Sub Form_Load()

    Me.tbxDate.Value = dtGetCurrentDate()  'this sets the date parameter
    Call cmdNext_Click 'this sets the cropID parameter - goes to the first item in the drop down list.

    Me.subfrmOrders.Form.RecordSource = "spGrowerOrder"
    Me.subfrmGrowerOrders.Form.InputParameters = "@Date smalldatetime = " & Me.tbxDate.Value & ", @Crop nvarchar(25) = " & Me.tbxCurrentCropID

End Sub
-------------

Any corrections to be made?  Thanks!
0
 
LVL 39

Expert Comment

by:stevbe
ID: 12056621
when you refer to a subform from it's parent you need to use the subform control name and not the name of the subform itself ...

Me.subformControlName.Form.InputParameters ....

Steve
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
LVL 1

Author Comment

by:rsoble
ID: 12056906
Oh yes I had a typo there.  It should have been:

    Me.subfrmOrders.Form.InputParameters = "@Date smalldatetime = " & Me.tbxDate.Value & ", @Crop nvarchar(25) = " & Me.tbxCurrentCropID

I fixed that and still am having problems.  I load the form and I get popups asking for my parameters.
I still think I probably have the syntax of the variable wrong?

0
 
LVL 39

Expert Comment

by:stevbe
ID: 12057038
Can you get the InputParameters to work if you do this on a single form ... we can fix Parent/Child references once this part is straight.

Steve
0
 
LVL 1

Author Comment

by:rsoble
ID: 12057110
With the subform alone, if I have the recordsource and the inputparameters set in the form properties, I then open the form in Form View and popups appear to put in the parameters.  I do so, and the subform appears populated with data as expected.  

If I open the main form in Form View and have the subform recordsouce set but the inputparameters blank, i am prompted for the two parameter value and after entering them, the form plus subform both load fine.  

So the problem is just trying to load the Parent+Subform with the input parameters being pulled from the parent rather than being input by hand.

Thanks.  I'll up the points to the max.
0
 
LVL 39

Accepted Solution

by:
stevbe earned 1500 total points
ID: 12057379
ok ... try leaving the InputParamters and RecordSDource properties blank and then setting the inputparameter poperty first ...

from Parent ...

'using Load to m,ake sure data is available ...
Private Sub Form_Load()
    me.childForm.Form.InputParamters = _
"@Date smalldatetime = " & Me.tbxDate.Value & ", @Crop nvarchar(25) = " & Me.tbxCurrentCropID
me.childForm.Form.Recordsource = "sproc_MyStoredProc"

End Sub
0
 
LVL 1

Author Comment

by:rsoble
ID: 12066089
Ok, that seemed to work, setting the input parameters first.  
But I also had to reformat my InputParameters string to include the little single quote marks that SQL needed:
Here's the final version:

================
Private Sub Form_Load()
    Me.tbxDate.Value = dtGetCurrentDate()
    Call cmdNext_Click
    Me.subfrmGrowerOrders.Form.InputParameters = "@Date smalldatetime = '" & DateValue(Me.tbxDate) & "', @Crop nvarchar(25) = '" & Me.tbxCurrentCropID & "'"
    Me.subfrmGrowerOrders.Form.RecordSource = "spGrowerOrder"
End Sub
================

Thanks for your help!  
0
 
LVL 1

Author Comment

by:rsoble
ID: 12068398
Steve - I'm posting a followup question to this one because now I've got another problem with this subform.  Check it out if you're interested.
0
 
LVL 1

Author Comment

by:rsoble
ID: 12068612
Nevermind, I'm not posting the followup yet.  I want to do more experimentation on my own first...  sorry for the false alarm.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question