473,608 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referencing problem

cmd
I have code in the OnExit event of a control on a subform. The code
works properly in this instance. If, however, I put the same code in
the OnExit event of a control on a Tab Control of a main form, the code
errors out at the 2nd line. The error number is 13 and the description
is "Type mismatch". Both controls are memo fields. I suspect that
"Screen.ActiveC ontrol.Parent" is not referencing the form as intended.

Thanks for any help,
Mark
'************** *******
Dim frm As Form
Set frm = Screen.ActiveCo ntrol.Parent
If frm.Dirty = True Then
frm.Dirty = False
End If

'(rest of the code)
'************** *******

Jul 25 '06 #1
21 5087
The Parent of a control is not necessarily the form.
It could be the tab control (your example), or another control (e.g. for an
attached label), or an option group (for a button in the group), or another
form (for a subform control), and so on.

Perhaps you could use use Form.ActiveCont rol, or pass a reference to the
control if you are calling a generic procedure.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<cm*@mountain.n etwrote in message
news:11******** **************@ s13g2000cwa.goo glegroups.com.. .
>I have code in the OnExit event of a control on a subform. The code
works properly in this instance. If, however, I put the same code in
the OnExit event of a control on a Tab Control of a main form, the code
errors out at the 2nd line. The error number is 13 and the description
is "Type mismatch". Both controls are memo fields. I suspect that
"Screen.ActiveC ontrol.Parent" is not referencing the form as intended.

Thanks for any help,
Mark
'************** *******
Dim frm As Form
Set frm = Screen.ActiveCo ntrol.Parent
If frm.Dirty = True Then
frm.Dirty = False
End If

'(rest of the code)
'************** *******

Jul 26 '06 #2
cmd
Thanks Allen, but I'm lost.

I checked my copy of the Access97 Developer's Handbook, 3rd ed. and
found several cautions against using Screen.ActiveCo ntrol and
Screen.ActiveFo rm. The suggestion was to use Me properties instead. But
"Me" isn't applicable in a global function -- right?

In this case, I don't think there's a problem using
Screen.ActiveCo ntrol, but there is trying to reference the
ActiveControl's form by using Screen.ActiveCo ntrol.Parent or
Screen.ActiveFo rm.

"Parent" is this case appears to be the TabControl or Page of the
TabControl on which the ActiveControl exists -- rather than the subform
itself.

I wasn't sure how to use your suggestion (Form.ActiveCon trol) -- I
tried using:

If Form.ActiveCont rol.Dirty = True Then
Form.ActiveCont rol.Dirty = False
End If

.... but I get an "object doesn't support this property or method"
error.

Thanks,
Mark
Allen Browne wrote:
The Parent of a control is not necessarily the form.
It could be the tab control (your example), or another control (e.g. for an
attached label), or an option group (for a button in the group), or another
form (for a subform control), and so on.

Perhaps you could use use Form.ActiveCont rol, or pass a reference to the
control if you are calling a generic procedure.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<cm*@mountain.n etwrote in message
news:11******** **************@ s13g2000cwa.goo glegroups.com.. .
I have code in the OnExit event of a control on a subform. The code
works properly in this instance. If, however, I put the same code in
the OnExit event of a control on a Tab Control of a main form, the code
errors out at the 2nd line. The error number is 13 and the description
is "Type mismatch". Both controls are memo fields. I suspect that
"Screen.ActiveC ontrol.Parent" is not referencing the form as intended.

Thanks for any help,
Mark
'************** *******
Dim frm As Form
Set frm = Screen.ActiveCo ntrol.Parent
If frm.Dirty = True Then
frm.Dirty = False
End If

'(rest of the code)
'************** *******
Jul 26 '06 #3
<cm*@mountain.n etwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
"Me" isn't applicable in a global function -- right?
PMFJI ... it is available if you pass the form object to the function.

Call libSomeFunction (Me)

libSomeFunction (frm As Form)

Regards,
Keith.
www.keithwilby.com
Jul 26 '06 #4
"cm*@mountain.n et" <cm*@mountain.n etwrote in message
<11************ **********@m79g 2000cwm.googleg roups.com>:
"Parent" is this case appears to be the TabControl or Page of the
TabControl on which the ActiveControl exists -- rather than the
subform itself.
You'd probably need some errorhandling, but try out this idea

Dim frm As Form
Dim ctl As Object

Set ctl = Screen.ActiveCo ntrol
Do While Not TypeOf ctl Is Form
Set ctl = ctl.Parent
Loop

If TypeOf ctl Is Form Then
Set frm = ctl
Else
MsgBox "ouch"
End If

--
Roy-Vidar
Jul 26 '06 #5
cmd
Thanks RoyVidar,

.... Debug.Print Screen.ActiveCo ntrol gives me the value of the control,
rather than the control name or type -- is "Set ctl =
Screen.ActiveCo ntrol" still what I want?

Thanks,
Mark

RoyVidar wrote:
"cm*@mountain.n et" <cm*@mountain.n etwrote in message
<11************ **********@m79g 2000cwm.googleg roups.com>:
"Parent" is this case appears to be the TabControl or Page of the
TabControl on which the ActiveControl exists -- rather than the
subform itself.

You'd probably need some errorhandling, but try out this idea

Dim frm As Form
Dim ctl As Object

Set ctl = Screen.ActiveCo ntrol
Do While Not TypeOf ctl Is Form
Set ctl = ctl.Parent
Loop

If TypeOf ctl Is Form Then
Set frm = ctl
Else
MsgBox "ouch"
End If

--
Roy-Vidar
Jul 26 '06 #6
cmd

Help! This is getting pretty frustrating and it seems that it shouldn't
be that much of a problem!

The spellcheck function (in a global module) which I have been using
works fine for controls on a mainform/subform layout. The function is
placed in the relevant controls' OnExit event. Spellcheck occurs as the
user tabs out of each field. Warnings are turned off during the event
to suppress the "Spellcheck is complete" message. The code is as
follows:

Dim frm As Form
Set frm = Screen.ActiveCo ntrol.Parent
If frm.Dirty Then
frm.Dirty = False
End If

On Error Resume Next

Dim L As Integer
L = Nz(Len(Screen.A ctiveControl), 0)
L = Len(Nz(Screen.A ctiveControl, ""))
If L 0 Then
With Screen.ActiveCo ntrol
.SetFocus
.SelStart = 0
.SelLength = L
End With

DoCmd.SetWarnin gs False
DoCmd.RunComman d acCmdSpelling
DoCmd.SetWarnin gs True
End If

This global function, however, does not work as is on a
mainform/subform/tabcontrol layout. The procedure does not recognize
"Screen.ActiveC ontrol.Parent" as the subform on which the
control/tabcontrol is placed -- hence, it errors at the line: "Set frm
= Screen.ActiveCo ntrol.Parent".

I can live without using this global function for layouts where I have
a subform with a tabcontrol on the subform. Therefore, I thought I
would try using the code as a local procedure and placed the code in
the OnExit event for a specific control on the tabcontrol of the
subform. I changed "Set frm = Screen.ActiveCo ntrol.Parent" to: "Set frm
= Me.Form" and apparently this works for this portion of the code.
Spellcheck works as it's supposed to, but the focus will not leave the
control. An error-handler reports the error number as "0" and there is
no error description.

I added a statement at the end which returns the focus to the
tabcontrol:
"Screen.ActiveC ontrol.Parent.S etFocus" and this resolves the problem of
getting stuck in the control. However, it also prevents the user from
simply tabbing from one field to the next.

I've tried other variations of spellchecking routines placed as a local
procedure for each control, but the focus also stays locked on the
current control -- e.g.:

(I changed "PreviousContro l" to "ActiveCont rol" since I wanted it to
run as an OnExit event, rather than from a command button.)

'************ Code Example 1 Start *************** *
' Adaptation by Terry Wickenden of code
' from Microsoft Knowledge Base

Private Sub cmdSpell_Click( )
Dim ctlSpell As Control

Set ctlSpell = Screen.Previous Control
If TypeOf ctlSpell Is TextBox Then
If IsNull(Len(ctlS pell)) Or Len(ctlSpell) = 0 Then
MsgBox "There is nothing to spell check."
ctlSpell.SetFoc us
Exit Sub
End If
With ctlSpell
.SetFocus
.SelStart = 0
.SelLength = Len(ctlSpell)
End With
DoCmd.RunComman d acCmdSpelling
Else
MsgBox "Spell check is not available for this item."
End If
ctlSpell.SetFoc us
End Sub
' *************** *** Code Example 1 End *************** *****

Jul 26 '06 #7
cm*@mountain.ne t wrote in
news:11******** *************@h 48g2000cwc.goog legroups.com:
... Debug.Print Screen.ActiveCo ntrol gives me the value of the
control, rather than the control name or type -- is "Set ctl =
Screen.ActiveCo ntrol" still what I want?
Since you'll be calling the external function from a context where
Me is meaningful, pass the control reference to your function. Then
test its parent until you get to its parent form:

If TypeOf ctl.parent = Form
ctl.parent.Requ ery
Else
ctl.parent.pare nt.Requery
End If

That's air code, so you'll have to change it appropriately to work
in all cases.

This method completely avoids the Screen.Activeco ntrol issues, which
I have never trusted.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 26 '06 #8
cmd
Thanks David for the response
.... but, "requery"?
.... I must be way over my head here because I have no idea what I would
be requerying.
Mark

David W. Fenton wrote:
cm*@mountain.ne t wrote in
news:11******** *************@h 48g2000cwc.goog legroups.com:
... Debug.Print Screen.ActiveCo ntrol gives me the value of the
control, rather than the control name or type -- is "Set ctl =
Screen.ActiveCo ntrol" still what I want?

Since you'll be calling the external function from a context where
Me is meaningful, pass the control reference to your function. Then
test its parent until you get to its parent form:

If TypeOf ctl.parent = Form
ctl.parent.Requ ery
Else
ctl.parent.pare nt.Requery
End If

That's air code, so you'll have to change it appropriately to work
in all cases.

This method completely avoids the Screen.Activeco ntrol issues, which
I have never trusted.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 26 '06 #9
cm*@mountain.ne t wrote in
news:11******** **************@ m79g2000cwm.goo glegroups.com:
... but, "requery"?
... I must be way over my head here because I have no idea what I
would be requerying.
I thought the context was requerying the parent form.

I just saw your other post about spell checking. I don't quite
comprehend why you'd want to spell check something in this fashion,
nor do I know if it's possible do to this with a subform.

However, I do know that you should be able to test what type of item
the .Parent is and then conditionally execute different code. The
parent of a control on a subform is the subform control, and you'd
want to find the name of that, and then use it to get a form
reference.

If Me.Parent is subform control and it is named "MySubForm" , you'd
refer to it as:

Me.Parent.Paren t("MySubForm"). Form

If the parent is a tab, you'd use:

Me.Parent.Paren t

to return a reference to the form the tab is embeded in.

If the tab is on a subform, you'd use:

Me.Parent.Paren t.Parent("MySub Form").Form

Make sense?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 26 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2455
by: jstaggs39 | last post by:
I want to create a Dcount and an If...Then...Else statement to count the number of records in a table based on the date that is entered to run the form. The If....Else statment comes in because if the amount of records for a particular date is positive, i want the form to stop running, if there are no records that contain the date in question, then it should continue to run the form. The problem i'm having is referencing the date that is...
2
1560
by: Jon Davis | last post by:
I have a full-blown application that consists of several (fifteen or so) assembly DLLs, each being a separate VS.NET project that outputs to the main DLL's bin directory. They are all strongly named. I have registered the main DLL, which references the other DLLs, to the GAC cache. I have built a plug-in for a third party application with which I load the GAC cached assembly. But it doesn't find the dependencies. I just spent hours...
4
1530
by: Edward Diener | last post by:
I have a class Y in assembly B which is derived from a class Z in assembly C. So I correctly add a reference to assembly C in assembly B, build assembly B and everything builds fine. Now I create an assembly A which refers to class Y in assembly B. So I add a reference in assembly A to assembly B, and attempt to build. I get an error message, C3264, saying that it could not find the type Z, and that it is in assembly C to which I have no...
6
2470
by: Mikey_Doc | last post by:
Hi We are running cms 2002, Framework 1.0 with Visual studio 2002. We have just upgraded to Framework 1.1 and visual studio 2003. All of our database connection strings are stored within the machine config, this was necessary as our web site has 4 environments and the database server has a different name in each. Since the upgrade the applications can't read the strings in the
11
2106
by: Daylor | last post by:
hi. im using option strict on. im doing in ,from the simple reason ,to be warn when there are implict conversion like string to int ,int to string. BUT. the price ,(now i see ), is very bad. if i have class CCar and interface ICar when im doing this : ICar = new CCar
1
2358
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been installed into the GAC. We originally had this assembly without a strong-name and we were successfully using it by referencing it when it was NOT in the GAC. The assembly was built using the 1.0 framework and we were able to call it from both 1.0...
4
1462
by: steve_barker333 | last post by:
Hi guys! I keep getting the following error reported by VS 2005 in my ASP.NET 2.0 web project: "The type or namespace name 'MainPages_XXX' could not be found (are you missing a using directive or an assembly reference?)" The line of C# code (in the "code-behind" file) that error refers to looks something like this:
1
921
by: Prashwee | last post by:
Hello All I have a simple problem with name space concept I have created an Add-in using a class library (let say the name of it is "ClassLibrary1") Then I added one form (say "Form1") and one class (say "Class1") Class1 is under the name space of "ifs.cadIntegeration:)
0
1600
by: Buglish | last post by:
Hi, Task : -Capture a HTML table with use of regular expression from a text string buffer(entire document). –Pass it to another function to create a multi dimension array out of it. - Pass it to another function to build it into a RTF table. -Then return it back to the regular expression to replace the search result. Difficulty: -The regular expression doesn’t pass the back referenced table fields to the next function.
0
8010
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8501
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6015
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5479
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3967
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4030
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1336
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.