A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

strange behavior in referring to control on another form



 
 
Thread Tools Display Modes
  #1  
Old January 16th, 2010, 04:54 PM posted to microsoft.public.access.forms
vircalendar via AccessMonster.com
external usenet poster
 
Posts: 31
Default strange behavior in referring to control on another form

I have two forms that are called by the same sub (using select case1 and
case2). VBA in one of the forms is able to refer to controls on the original
form (which remains open) without using the full qualified name (forms!
[firstform]![control]), but the other one is not. Any idea why that might be?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201001/1

  #2  
Old January 16th, 2010, 07:07 PM posted to microsoft.public.access.forms
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default strange behavior in referring to control on another form

Best practices would require using:

Me.ControlName
or:
Forms!FormName!ControlName

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"vircalendar via AccessMonster.com" u4313@uwe wrote in message
news:a2346d4c8ccfa@uwe...
I have two forms that are called by the same sub (using select case1 and
case2). VBA in one of the forms is able to refer to controls on the
original
form (which remains open) without using the full qualified name (forms!
[firstform]![control]), but the other one is not. Any idea why that might
be?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201001/1



  #3  
Old January 16th, 2010, 10:04 PM posted to microsoft.public.access.forms
vircalendar via AccessMonster.com
external usenet poster
 
Posts: 31
Default strange behavior in referring to control on another form

Agreed. The problem is that the fully qualified name gets pretty long since
there are also subforms in the mix.

I still don't understand why one of the two forms is able to refer back to
controls on the original without the Forms!FormName part of the name (in
other words, its code works when I simply say "ControlName") and the other
one requires the full Forms!FormName!ControlName. I'm still missing something.


While we're on the subject of qualified names, is there any way to refer to a
long qualified name with a string? This works, but only for naming the
parent form:

Private Sub Command0_Click()
dim frmtest as string
frmtest = "FormName"
Forms(frmtest)!SubformNamet!ControlName = Text1
End Sub

This doesn't work:

Private Sub Command0_Click()
dim frmtest as string
frmtest = "FormName!SubformName"
Forms(frmtest)!ControlName = Text1
End Sub

Arvin Meyer [MVP] wrote:
Best practices would require using:

Me.ControlName
or:
Forms!FormName!ControlName

I have two forms that are called by the same sub (using select case1 and
case2). VBA in one of the forms is able to refer to controls on the
original
form (which remains open) without using the full qualified name (forms!
[firstform]![control]), but the other one is not. Any idea why that might
be?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201001/1

  #4  
Old January 18th, 2010, 02:00 PM posted to microsoft.public.access.forms
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default strange behavior in referring to control on another form

I'm not sure I'm following all of this, but to refer to a control on a
subform from anywhere other than the subform itself you need to first
reference the Form property of the subform control. From the main form this
could be:

Me.SubformControlName.Form.ControlName

In fully qualified format:

Forms!FormName!SubformControlName.Form!ControlName

I don't understand the objective of this code:
Forms(frmtest)!SubformNamet!ControlName = Text1

However, if it works, this should work to reference the control on the
subform:

Forms(frmtest)!SubformName.Form!ControlName = Text1

I don't know the extent to which you can use a string for the fully qualified
name. You could do so if you were assembling a SQL string in VBA, but again
I am a bit unclear on your objective. If I need to reference a value
repeatedly in code, whether the value is in a control on the current form or
on a separate form I tend to assign the value to a variable, and thereafter
refer to the variable:

Dim strControlValue as String

strControlValue = Forms!MainFormName!SubformControlName.Form!Control Name

I have done a little testing, and it seems you can reference multiple
controls on the subform thus:

Dim strValue1 as String, strValue2 as String

With Forms!MainFormName!SubformControlName.Form
strValue1 = !Control1
strValue2 = !Control2
End With

In either example, refer to the string rather than the control the next time
you need it in the procedure.

Of course, if the value is something other than a string, Dim the variable
appropriately. For instance, if Control1 is a String and Control2 is Long
Integer:

Dim strValue as String
Dim lngValue as Long

With Forms!MainFormName!SubformControlName.Form
strValue = !Control1
lngValue = !Control2
End With

vircalendar wrote:
Agreed. The problem is that the fully qualified name gets pretty long since
there are also subforms in the mix.

I still don't understand why one of the two forms is able to refer back to
controls on the original without the Forms!FormName part of the name (in
other words, its code works when I simply say "ControlName") and the other
one requires the full Forms!FormName!ControlName. I'm still missing something.

While we're on the subject of qualified names, is there any way to refer to a
long qualified name with a string? This works, but only for naming the
parent form:

Private Sub Command0_Click()
dim frmtest as string
frmtest = "FormName"
Forms(frmtest)!SubformNamet!ControlName = Text1
End Sub

This doesn't work:

Private Sub Command0_Click()
dim frmtest as string
frmtest = "FormName!SubformName"
Forms(frmtest)!ControlName = Text1
End Sub

Best practices would require using:

[quoted text clipped - 8 lines]
[firstform]![control]), but the other one is not. Any idea why that might
be?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201001/1

  #5  
Old January 21st, 2010, 02:31 PM posted to microsoft.public.access.forms
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default strange behavior in referring to control on another form

A subform is not a form, it is a control that has a form property. So to
reference a subform use:

Me.NameOfSubformControl.Form.ControlNameOnThatForm

from within the subform, you can use:

Me.Parent.ControlNameOnParent

the bang (!) may be subsitituted for the dot(.) in both cases, except to
identify the form properties, which must always use the dot (.)

Me, Parent, and Form are keywords. The rest are names or descriptions which
are placeholders.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"vircalendar via AccessMonster.com" u4313@uwe wrote in message
news:a23720f2e1815@uwe...
Agreed. The problem is that the fully qualified name gets pretty long
since
there are also subforms in the mix.

I still don't understand why one of the two forms is able to refer back to
controls on the original without the Forms!FormName part of the name (in
other words, its code works when I simply say "ControlName") and the other
one requires the full Forms!FormName!ControlName. I'm still missing
something.


While we're on the subject of qualified names, is there any way to refer
to a
long qualified name with a string? This works, but only for naming the
parent form:

Private Sub Command0_Click()
dim frmtest as string
frmtest = "FormName"
Forms(frmtest)!SubformNamet!ControlName = Text1
End Sub

This doesn't work:

Private Sub Command0_Click()
dim frmtest as string
frmtest = "FormName!SubformName"
Forms(frmtest)!ControlName = Text1
End Sub

Arvin Meyer [MVP] wrote:
Best practices would require using:

Me.ControlName
or:
Forms!FormName!ControlName

I have two forms that are called by the same sub (using select case1 and
case2). VBA in one of the forms is able to refer to controls on the
original
form (which remains open) without using the full qualified name (forms!
[firstform]![control]), but the other one is not. Any idea why that
might
be?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201001/1



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:01 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.