Using Tag property to Requery another form

  • Thread starter Thread starter Bradley C. Hammerstrom
  • Start date Start date
B

Bradley C. Hammerstrom

A2K,

I'm trying to have a control on another form refresh when the OK button is
clicked on a small pop-up form that the user used to edit the text in the
control on the other form. The pop-up edit form, mbxEditFN, is fired by the
double-click event of the control and I save the name of the form in the Tag
property of the mbx. I can see it in the Tag property so I that much is
working.

Now after the user edits the text and clicks OK, I want the original control
to refresh to show the edited text like this:

Dim ctlControlName As Control
Set ctlControlName = Forms.mbxEditFN.Tag
ctlControlName.Requery

the Tag is [Forms]![frmMain].[Description] and is the name of a text box
control.

I plan to use the same mbx called from a few different forms; that's why I
need the mbx to "remember" which form called it by using the Tag property.

Brad.
 
Dim ctlControlName As Control
Set ctlControlName = Forms.mbxEditFN.Tag
ctlControlName.Requery

ctlControlName is a variable of type Control, while the Tag property returns
a value of type String. You can't assign the string value to the control
variable, you need to get the control to which the string value refers ...

Public Sub TagToControl()

Dim strForm As String
Dim strControl As String
Dim ctl As Control

'For testing only.
Const strcFormControl As String = "[Forms]![frmMain].[Description]"

strForm = Mid$(strcFormControl, InStr(1, strcFormControl, "!") + 2)
strForm = Left$(strForm, InStr(1, strForm, "]") - 1)
Debug.Print strForm

strControl = Mid$(strcFormControl, InStr(1, strcFormControl, ".") + 2)
strControl = Left$(strControl, InStr(1, strControl, "]") - 1)
Debug.Print strControl

'Commented out because of course there is no such form on my system.
'Set ctl = Forms(strForm).Controls(strControl)

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.


Bradley C. Hammerstrom said:
A2K,

I'm trying to have a control on another form refresh when the OK button is
clicked on a small pop-up form that the user used to edit the text in the
control on the other form. The pop-up edit form, mbxEditFN, is fired by
the
double-click event of the control and I save the name of the form in the
Tag
property of the mbx. I can see it in the Tag property so I that much is
working.

Now after the user edits the text and clicks OK, I want the original
control
to refresh to show the edited text like this:

Dim ctlControlName As Control
Set ctlControlName = Forms.mbxEditFN.Tag
ctlControlName.Requery

the Tag is [Forms]![frmMain].[Description] and is the name of a text box
control.

I plan to use the same mbx called from a few different forms; that's why I
need the mbx to "remember" which form called it by using the Tag property.

Brad.
 
Brendan,

It's not quite there yet. The last lines are:

Set ctl = Forms(strForm).Controls(strControl)
Debug.Print ctl

What prints is the actual text in the Description textbox; not the control
name.

However, strForm and strControl both print correctly.

Additionally, I still need a way to refer to the Tag string to name the
control because the control name will vary depending on which form called
the mbx. That is why I am using the Tag--to store the calling form.

I tied adding this (doesn't work):

Dim strTag
strTag = Forms.mbxEditFN.Tag
Debug.Print strTag 'correctly prints, "[Forms]![frmMain].[Description]"
Const strcFormControl As String = strTag

But I get a Compile Error: Constant Expression Required with the strTag
highlighted.

What do you think?

Brad H.


Brendan Reynolds said:
Dim ctlControlName As Control
Set ctlControlName = Forms.mbxEditFN.Tag
ctlControlName.Requery

ctlControlName is a variable of type Control, while the Tag property returns
a value of type String. You can't assign the string value to the control
variable, you need to get the control to which the string value refers ...

Public Sub TagToControl()

Dim strForm As String
Dim strControl As String
Dim ctl As Control

'For testing only.
Const strcFormControl As String = "[Forms]![frmMain].[Description]"

strForm = Mid$(strcFormControl, InStr(1, strcFormControl, "!") + 2)
strForm = Left$(strForm, InStr(1, strForm, "]") - 1)
Debug.Print strForm

strControl = Mid$(strcFormControl, InStr(1, strcFormControl, ".") + 2)
strControl = Left$(strControl, InStr(1, strControl, "]") - 1)
Debug.Print strControl

'Commented out because of course there is no such form on my system.
'Set ctl = Forms(strForm).Controls(strControl)

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.


Bradley C. Hammerstrom said:
A2K,

I'm trying to have a control on another form refresh when the OK button is
clicked on a small pop-up form that the user used to edit the text in the
control on the other form. The pop-up edit form, mbxEditFN, is fired by
the
double-click event of the control and I save the name of the form in the
Tag
property of the mbx. I can see it in the Tag property so I that much is
working.

Now after the user edits the text and clicks OK, I want the original
control
to refresh to show the edited text like this:

Dim ctlControlName As Control
Set ctlControlName = Forms.mbxEditFN.Tag
ctlControlName.Requery

the Tag is [Forms]![frmMain].[Description] and is the name of a text box
control.

I plan to use the same mbx called from a few different forms; that's why I
need the mbx to "remember" which form called it by using the Tag property.

Brad.
 
Bradley C. Hammerstrom said:
Brendan,

It's not quite there yet. The last lines are:

Set ctl = Forms(strForm).Controls(strControl)
Debug.Print ctl

What prints is the actual text in the Description textbox; not the control
name.

That's as expected. The defalut property of a control is the Value property.
If you want the Name, specify it ...

Debug.Print ctl.Name
However, strForm and strControl both print correctly.

Additionally, I still need a way to refer to the Tag string to name the
control because the control name will vary depending on which form called
the mbx. That is why I am using the Tag--to store the calling form.

Did you notice the comment 'for testing only' in the code I posted? I used a
constant instead of the Tag property so that I could quickly test the code
without having to recreate your forms and controls. You should continue to
use the Tag property.
I tied adding this (doesn't work):

Dim strTag
strTag = Forms.mbxEditFN.Tag
Debug.Print strTag 'correctly prints, "[Forms]![frmMain].[Description]"
Const strcFormControl As String = strTag

But I get a Compile Error: Constant Expression Required with the strTag
highlighted.

What do you think?

Brad H.


Brendan Reynolds said:
Dim ctlControlName As Control
Set ctlControlName = Forms.mbxEditFN.Tag
ctlControlName.Requery

ctlControlName is a variable of type Control, while the Tag property returns
a value of type String. You can't assign the string value to the control
variable, you need to get the control to which the string value refers
...

Public Sub TagToControl()

Dim strForm As String
Dim strControl As String
Dim ctl As Control

'For testing only.
Const strcFormControl As String = "[Forms]![frmMain].[Description]"

strForm = Mid$(strcFormControl, InStr(1, strcFormControl, "!") + 2)
strForm = Left$(strForm, InStr(1, strForm, "]") - 1)
Debug.Print strForm

strControl = Mid$(strcFormControl, InStr(1, strcFormControl, ".") +
2)
strControl = Left$(strControl, InStr(1, strControl, "]") - 1)
Debug.Print strControl

'Commented out because of course there is no such form on my system.
'Set ctl = Forms(strForm).Controls(strControl)

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible
for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.


Bradley C. Hammerstrom said:
A2K,

I'm trying to have a control on another form refresh when the OK button is
clicked on a small pop-up form that the user used to edit the text in the
control on the other form. The pop-up edit form, mbxEditFN, is fired by
the
double-click event of the control and I save the name of the form in
the
Tag
property of the mbx. I can see it in the Tag property so I that much is
working.

Now after the user edits the text and clicks OK, I want the original
control
to refresh to show the edited text like this:

Dim ctlControlName As Control
Set ctlControlName = Forms.mbxEditFN.Tag
ctlControlName.Requery

the Tag is [Forms]![frmMain].[Description] and is the name of a text
box
control.

I plan to use the same mbx called from a few different forms; that's
why I
need the mbx to "remember" which form called it by using the Tag property.

Brad.


--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Back
Top