stLinkCriteria to SubForm

groupy

Registered User.
Local time
Today, 14:01
Joined
Dec 17, 2001
Messages
33
Hi,

I have a big and urgent problem.

I have a form with a subform. The form don't have a recordsource, only buttons. The subform is a datasheet.

I want to open de form with a stLinkCriteria, but the stLinkCriteria is not for the form, but for the subform.

Example:

stDocName = "formTest"
stLinkCriteria = "[forms]![formTest]![formTestSub]!
Code:
 = 1"
DoCmd.openForm stDocName, , , stLinkCriteria

This is not working.

Can someone help me.

Thanks
 
Try this instead of the code you have already.


Code:
DoCmd.OpenForm "formTest", , , , , , 1


And then, on the Form_Load event of formTest

Code:
Forms!formTest!formTestSub!code = 1
 
Thanks for you're reaction, but it is not the solotion:

I will explain the problem further, the stLinkCriteria is variable, not every time '1':

stDocName = "formTest"
stLinkCriteria = "[forms]![formTest]![formTestSub]!
Code:
 In (SELECT code From tblTest Where name = " & varName
DoCmd.openForm stDocName, , , stLinkCriteria 

When I open the subform direct, without formTest, the stLinkCriteria works, but when I open the formTest with subform the stLinkCriteria don't work. I think because
forms]![formTest]![formTestSub]![code] is not right.

The problem is the link to the field 'code' on the subform.

I really hope someone can help me.

Thanks.
 
You do realise that using the string variable stLinkCriteria is trying to open the form formTest at the specific record in it's ControlSource but you say that this form is not bound to anything so it will never find anything.

Now, I don't know the reason why your subform has records yet your parent has not underlying records. I won't ask.

So, when opening the form formTest you will need to send the criteria into the form's OpenArgs property. Then, as I've said, use the form formTest's Load event to requery the subform's recordsource. Firstly, have a hidden control on the parent form that you assign the value of the OpenArgs to. Then ensure that the subform's ControlSource is a query with the Code field having the criteria that references the hidden control on the parent.
 
Thanks for you're reply,

I understand what you want, but I have one little problem. I can get the openArg in a txtfield.

I add to control source to txtfield:
=[OpenArgs]

But The txtfield don't show anythink, even when it is visible.

Do you now the solution.

I'm sorry I ask you again, but I hope you can help me.

Thanks
 
Just code it:

Code:
Private Sub Form_Load()
   Me.txtHidden = Me.OpenArgs
End Sub


where txtHidden is the hidden textbox.
 
An Access '97 version please...:(
 
Hi,

Thanks for you're reply, but the most difficult part is missing. Because it must be also possible to select 2 items in the listbox. For example 1 and 2 and the next time 1 and 3.

I hope you have a solution for that.

Thanks a lot.
 
Not the tidiest to understand...but I just don't have that sort of time today. :(


Cheers to dcx, too, for some of the code as I didn't have the time to write anything.
 

Attachments

Hi Mile-O-Phile,

Thanks a lot for you're help. My application is working now.

One comment, I changed:

'Me.[subform].SourceObject = SQLName' in
'Me.[subform].Form.RecordSource = SQLName'

And than everythink works great.

Thanks a lot.
 

Users who are viewing this thread

Back
Top Bottom