Before I launch into the answer, I notice you're passing the name of a form
and control to a zoom form, so it can read/write the control value. To me,
the better structure would be to have the function handle reading/writing the
control and pass only the text value to and from the popup. It doesn't change
your question much though, because you still might have to pass text longer
than what OpenArgs will take.
Also, since you're passing the control object, why do you need the form name?
You could write the value back to the control and not care what form it
happens to be on. For code like this that's likely to be called from an event
handler, though, I actually like to pass the form object, and the control
name, then all the error handling responsibility is in the generic function, -
even if the control cannot be referenced.
One last thing - why is Asset Location's zoom different than anything else's
zoom? Couldn't it just be Zoom?
So...
As you've noticed, since you're opening the form as acDialog, you can't write
data to the form's controls after opening it because your code is already
waiting for the form to close when the calling code could run to do that. You
have no choice but to write the values to some kind of variable storage, then
have the dialog form read values from that storage when it opens. A similar
problem occurs trying to pass multiple parameters to a report.
I like to do it sort of like this (untested)...
== In a public module ===
Private mcolObjParamSets As VBA.Collection
Public Sub PushObjectParamSet( _
ObjectName As String, _
ParamSet As Variant _
)
'Make sure any old set is removed first
On Error Resume Next
mcolObjParamSets.Remove
On Error Goto 0: Err.Clear
mcolObjParamSets.Add Key:=ObjectName, _
Item:=ParamSet
End Sub
'Return via reference parameter, so it will work
'the same regardless of whether it's an object or
'a scalar or array.
Public Sub PopObjectParamSet( _
ObjectName As String, _
ByRef ParamSet As Variant _
)
CopyVarContent FromVar:=mcolObjParamSets(ObjectName), _
ToVar:=ParamSet
On Error Resume Next
mcolObjParamSets.Remove
On Error Goto 0: Err.Clear
End Sub
'Copies the content of one variable to another
'regardless of whether the content is an object
'or an non-object value.
Public Sub CopyVarContent( _
FromVar As Variant, _
ByRef ToVar As Variant _
)
If IsObject(FromVar) Then
Set ToVar = FromVar
Else
ToVar = FromVar
Endif
End Sub
== Code to open the dialog ===
Public Sub ZoomValue(Form As Form, CtrlName As String, Caption As String)
Const cstrZoomFormName = "frmZoomValue"
On Error GoTo err_zoom
strFormName = formName
Dim colParams As New VBA.Collection
colParams.Add Key:="Text", _
Item:=Form.Controls(CtrlName).Value
colParams.Add Key:="Caption", _
Item:=Caption
PushObjectParamSet cstrZoomFormName, colParams
DoCmd.openform Name:=cstrZoomFormName, _
WindowMode:=acDialog
'rather than hiding itself, so we can examine its state,
'The form modifies the params object to return data,
'and closes. That way we don't have to couple this code
'to the form's design implementation.
If colParams("Response") = "OK" Then
Form.Controls(CtrlName).Value = colParams("Text")
End If
proc_final:
Exit Sub
err_catch:
MsgBox Err.Description & " " & Err.number
Resume proc_final
End Sub
=====
I don't have time to type the rest of an example right now, but the zoom form
will pop the parameter set collection, and use the items in it to initialize
itself. On return, it will delete and replace the "Text" item in the
collection and add the "Response" item to say what button was pushed.
On Thu, 22 Dec 2005 12:57:30 -0000, "Deano" <de***@mailinator.com> wrote:
Apparently you can only do this with one value i.e Call
MyAssetLocationZoom(Me!txtLocation, "Amend data")
This runs;
Public Sub MyAssetLocationZoom(ctl As Control, formName As String)
On Error GoTo err_zoom
strFormName = formName
DoCmd.openform "frmAssetLocZoom", , , , , acDialog, ctl.Value
If Forms!frmAssetLocZoom.Tag <> "Cancel" Then
ctl = Forms!frmAssetLocZoom!txtText
End If
DoCmd.Close acForm, "frmAssetLocZoom"
exit_err_zoom:
Exit Sub
err_zoom:
MsgBox Err.Description & " " & Err.number
Resume exit_err_zoom
End Sub
To put this into context, I have a form with a single field. The user
selects a value and clicks edit. A popup form appears with this value ready
to be edited. The above code handles all of that nicely.
I'd love to be able to do this with more than one value. Any ideas? I'm
looking at taggedvalues from the Access 2000 Developers Handbook but not
having much luck.
thanks
Martin