Parameterizing a "new Form"

M

Max Yaffe

I'm trying to implement multiple forms as per the "Access 2002 Devel.
Handbook" by Letwin, et.al. Here's my code to create a new form:

Public Sub NewBuycard(myPart As String)
Dim frm As Form_frmBuyCard

Set frm = New Form_frmBuyCard

' Do some bookkeeping here so form doesn't disappear at End Sub
...

frm.Visible = True
End Sub

This works fine (Thanks guys). It triggers the Form_Open code with
Me.OpenArgs set to Null which I show here:

Private Sub Form_Open(Cancel As Integer)

Dim S As String

If IsNull(Me.OpenArgs) Then
Me.Openargs = <some default value>
End If

' Do something with OpenArgs here
SetPart (Me.OpenArgs)

End Sub


But I'd really like to create a parameterized form in which OpenArgs
is set correctly. Ideally there should be something like

Set frm = New Form_frmBuyCard myPart

which would call Form_Open with OpenArgs set to myPart. Alas, that
doesn't work.

Is there any way I can have my cake and eat it too?

Thanks,
Max
 
D

Douglas J. Steele

You could have a hidden field on the form, and set it to whatever's in
myPart, and have the form look there to decide what to do.
 
M

Max Yaffe

Thanks, Doug but that really doesn't help.

When the New Form_BuyCard fires, it calls Form_Open at some point.
But the New doesn't have a way to set a field on the new form until it
returns. So during the call to Form_Open, Me.OpenArgs is alway null.
Do you see the catch-22?

Max
 
D

Douglas J. Steele

I didn't say to use OpenArgs. You're absolutely right that it'll always be
null. What I suggested was to add a hidden field on the form, and populate
that hidden field from your calling routine. Add a public routine in the
second form that does the same calculations you wanted to do with the
OpenArgs value, but have it use the hidden field's values, not OpenArgs.
Call the public routine from the calling routine after it's set the value in
the hidden field.
 
M

Max Yaffe

I guess that's what I'll have to do. It would have been nice if that
value could be set before the Form_Open fires but since I don't have a
handle to the form, I don't think I can set it. Unless you know of a
way to get it set before hand...

Otherwise, thanks anyway.
Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top