By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,345 Members | 1,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,345 IT Pros & Developers. It's quick & easy.

A2K - passing more than one value into a popup form

P: n/a
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
Dec 22 '05 #1
Share this Question
Share on Google+
13 Replies

P: n/a
I posted some air code in response a while ago. It hasn't shown up yet. To
assure that it does so immediately, I'll post something else:

Sub blah2()

' the form is call FFDBACheques
' it has a module
' or at least the HasModule Property set to True

With Form_FFDBACheques
.Visible = False
.txtfldDate = VBA.Date
.txtfldAmount = 1000
.Tag = "Whatever"
.Visible = True
End With

End Sub

--
Lyle Fairfield
Dec 22 '05 #2

P: n/a
Air code (assumes frmAssetLocZoom's HasModule property has been set to
true);

With Form_frmAssetLocZoom
.Visible = False
.SomeControl.Value = 42
.SomeOtherControl.Value = "Hi there, I am a Leo. What's your sign?"
.... whatever
.Visible = True
End With

Dec 22 '05 #3

P: n/a
Lyle Fairfield wrote:
Air code (assumes frmAssetLocZoom's HasModule property has been set to
true);

With Form_frmAssetLocZoom
.Visible = False
.SomeControl.Value = 42
.SomeOtherControl.Value = "Hi there, I am a Leo. What's your sign?"
.... whatever
.Visible = True
End With


Hmm, where does this With structure go? Also i'm trying to assign the
values of an underlying form to the popup form, so;

popupform.txt1 = mainform.txtsomevalue
popupform.txt2 = mainform.txtsomevalue2

I can't assign hardcoded values.
Dec 22 '05 #4

P: n/a
If I'm understanding the problem and objective correctly (which I am
prone to neglecting), you want to pass a bunch of values to your
subroutine, which will then populate your form's textboxes with the
passed-in values.

Apparently I definitely have missed the true goal here because it seems
way too simple. However, I will post my solution to this problem
regardless, in the interest of public humor.

Your subroutine signature is thus:
Public Sub MyAssetLocationZoom(ctl As Control, formName As String)

Is there a reason you can't just stick in some extra variables there?
I.e:

Public Sub MyAssetLocationZoom(ctl As Control, formName As String,
Optional val1 as String="", Optional val2 as String="")

Then you could simply populate your fields with the passed-in values.

As I said before, I must be missing something because I KNOW the other
posters in this thread must have already thought of adding more
variables to the sub sig.

Dec 22 '05 #5

P: n/a
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


Dec 22 '05 #6

P: n/a
On Thu, 22 Dec 2005 08:33:19 -0800, Steve Jorgensen <no****@nospam.nospam>
wrote:

....
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)...

....

David Fenton is likely to chime in that a wrapper object would be an even
better implementation, and he'll be right. If I have time, I'll post another
example that uses the same idea and a wrapper object instead of a collection
for passing the arguments back and forth.
Dec 22 '05 #7

P: n/a
Steve Jorgensen wrote:
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.
Oh the form name is just for the form caption.

One last thing - why is Asset Location's zoom different than anything
else's zoom? Couldn't it just be Zoom?
You're right there, it makes no odds at the moment and I am reusing it for
other forms, so it would be neater if it was just called Zoom.

So...


<snipped code>

Cripes, thank you very very much for all that. I will need a while to
digest it but it looks interesting.

Mucho thanks.
Dec 22 '05 #8

P: n/a
Steve wrote:
If I'm understanding the problem and objective correctly (which I am
prone to neglecting), you want to pass a bunch of values to your
subroutine, which will then populate your form's textboxes with the
passed-in values.

Apparently I definitely have missed the true goal here because it
seems way too simple. However, I will post my solution to this problem
regardless, in the interest of public humor.

Your subroutine signature is thus:
Public Sub MyAssetLocationZoom(ctl As Control, formName As String)

Is there a reason you can't just stick in some extra variables there?
I.e:

Public Sub MyAssetLocationZoom(ctl As Control, formName As String,
Optional val1 as String="", Optional val2 as String="")

Then you could simply populate your fields with the passed-in values.

As I said before, I must be missing something because I KNOW the other
posters in this thread must have already thought of adding more
variables to the sub sig.


To be honest I think it is quite simple and I have sorted out a hacked
solution using public variables, which knowing the way I code, probably
isn't the best way of doing it.

I don't know where I read it but it did say you can't pass more than one
control value across and you have to use tags or the way I did it
presumably. I haven't seen your above syntax so I will give that a go as
well.

Thanks.
Dec 22 '05 #9

P: n/a
I haven't got a clue about whether you can pass more than one Control
object into a subroutine. However, you could just pass the text values
of your controls into the sub. I do know you can only pass one object
into OpenArgs, if that's what you mean - but you can pass, say, a
comma-delimited string into OpenArgs and parse it out on the receiving
side. If you're trying to get values from the second form into the
first, you can use the syntax Forms!frmFormName1!ctlName , as you've
already done for a few other things.

Dec 22 '05 #10

P: n/a
Steve Jorgensen <no****@nospam.nospam> wrote in
news:ng********************************@4ax.com:
On Thu, 22 Dec 2005 08:33:19 -0800, Steve Jorgensen
<no****@nospam.nospam> wrote:

...
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)...

...

David Fenton is likely to chime in that a wrapper object would be
an even better implementation, and he'll be right. If I have
time, I'll post another example that uses the same idea and a
wrapper object instead of a collection for passing the arguments
back and forth.


Saved me the post!

In any event, for zoom I just use the built-in one from the wizard,
using the technique from A97 that was made possible by MS's very
kind decision to allow Getz & Litwin et al. to release the wizard
source code in the ADH97. It still works in A2K, but I've not used
it in any version beyond that. It is called like this in A97/A2k:

Application.Run("UTILITY.BuilderZoom", strObjName, strCtlName, _
strCurrValue, strFontName, intFontWeight, intFontSize)

For the general problem, though, I definitely vote for wrappers of
some sort, whether a full class module, or just some kind of wrapper
function.

It's too bad that OpenArgs is a string argument only, since then you
could pass arrays through it.

On the other hand, perhaps you could pass it a delimited list and
parse that into an array (I've been dealing with exactly that in a
PHP application I'm using, and it's pretty helpful).

But, of course, that's basically what the ADH Tag code does, and I
object to that, so I'm not certain why this alternative appeals to
me. Perhaps I've not thought it through properly.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Dec 22 '05 #11

P: n/a
"Deano" <de***@mailinator.com> wrote in
news:43***********************@ptn-nntp-reader03.plus.net:
Steve Jorgensen wrote:
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.


Oh the form name is just for the form caption.


Why not use ctl.Parent.Name?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Dec 22 '05 #12

P: n/a
"Steve" <th*********@gmail.com> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
If I'm understanding the problem and objective correctly (which I
am prone to neglecting), you want to pass a bunch of values to
your subroutine, which will then populate your form's textboxes
with the passed-in values.

Apparently I definitely have missed the true goal here because it
seems way too simple. However, I will post my solution to this
problem regardless, in the interest of public humor.

Your subroutine signature is thus:
Public Sub MyAssetLocationZoom(ctl As Control, formName As String)

Is there a reason you can't just stick in some extra variables
there? I.e:

Public Sub MyAssetLocationZoom(ctl As Control, formName As String,
Optional val1 as String="", Optional val2 as String="")

Then you could simply populate your fields with the passed-in
values.

As I said before, I must be missing something because I KNOW the
other posters in this thread must have already thought of adding
more variables to the sub sig.


Well, assuming you're opening the zoom form as a dialog, how do you
pass multiple values into it? Short answer: you can't, without
overloading OpenArgs or using an outside storage structure (which is
what Steve suggested).

Your approach works only when you're not using a dialog,

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Dec 22 '05 #13

P: n/a
"Steve" <th*********@gmail.com> wrote in
news:11*********************@z14g2000cwz.googlegro ups.com:
I haven't got a clue about whether you can pass more than one
Control object into a subroutine. However, you could just pass the
text values of your controls into the sub. I do know you can only
pass one object into OpenArgs, if that's what you mean - but you
can pass, say, a comma-delimited string into OpenArgs and parse it
out on the receiving side. If you're trying to get values from the
second form into the first, you can use the syntax
Forms!frmFormName1!ctlName , as you've already done for a few
other things.


Wouldn't we all assume that a zoom form would be opened modally, as
a dialog? If so, then you couldn't assign values after it opened,
because execution pauses until the dialog is closed or hidden.

Thus, the only alternatives are to overload OpenArgs (which is
messy) or to use an outside data structure. This latter is my
preference, using a class module, but you could use a custom
collection, too, with or without a wrapper class.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Dec 22 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.