Set dynamic reference to a control in a public function

0

0 1

On frmABC, I click a command button to open any of several popup
forms. The relevant code that opens the forms is:

###

Dim blRet As Boolean
blRet = PositionFormRelativeToControl(stDocName, stLinkCriteria,
Me.cmdViewEvent, 4)

###

PositionFormRelativeToControl is a public function that opens up the
forms in a certain location using twips, API, and a lot of other stuff
I don't understand. I've tweaked it a little. The relevant code for
the function is:

###

Public Function PositionFormRelativeToControl(frmName As String,
stLinkCriteria As String, ctl As Access.Control, Optional Position As
Long = 0) As Boolean

....

DoCmd.openForm frmName, , , stLinkCriteria, OpenArgs:=Forms!
frmPatients!PatientID

###

Notice I've hard coded the OpenArgs reference to refer to PatientID on
frmPatients.

Now I want to use this same function, but with a different form for
which the PatientID reference won't work. The OpenArgs: value for this
second form needs to be:

OpenArgs:=Forms!frmSurgery!SurgID

How can I make the public function more generic by not hard coding the
OpenArgs values (and perhaps instead set it at the form level)?

Thank you.
 
0

0 1

I should add that I have this in the OnLoad event of the popup forms:

If Not IsNull(Me.OpenArgs) Then
Me.PatientID.DefaultValue = """" & Me.OpenArgs & """"
ElseIf IsNull(Me.OpenArgs) Then
...

So, for this new set of popup forms, I would change this to:

Me.SurgID.DefaultValue = """" & Me.OpenArgs & """"
 

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