dbTalk Databases Forums  

Re: Referring to the With . . . End With Object

comp.databases.ms-access comp.databases.ms-access


Discuss Re: Referring to the With . . . End With Object in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Andy
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-26-2003 , 06:06 AM






peter (AT) SunSpotCompDot (DOT) ComDot.Au (Peter Nurse) wrote in message news:<3efa4c16.8660945 (AT) news (DOT) bigpond.com>...
<<>>
Quote:
Yes, I know about ".Value". I've struck this issue on a number of
different occasions but in this case I'm calling a routine which
updates the StatusBar & ControlTipText properties in tandem as shown
below...

Function UpdateStatusBarControlTip(Ctl As Control, Text As String)
On Error Resume Next
With Ctl
.StatusBarText = Text
.ControlTipText = Text
End With
On Error GoTo 0
End Function

Any ideas about the original question?
What's the problem with that code?


Reply With Quote
  #2  
Old   
Peter Nurse
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-26-2003 , 05:26 PM






On 26 Jun 2003 04:06:38 -0700, aon14 (AT) lycos (DOT) co.uk (Andy) wrote:

Quote:
peter (AT) SunSpotCompDot (DOT) ComDot.Au (Peter Nurse) wrote in message news:<3efa4c16.8660945 (AT) news (DOT) bigpond.com>...

Yes, I know about ".Value". I've struck this issue on a number of
different occasions but in this case I'm calling a routine which
updates the StatusBar & ControlTipText properties in tandem as shown
below...

Function UpdateStatusBarControlTip(Ctl As Control, Text As String)
On Error Resume Next
With Ctl
.StatusBarText = Text
.ControlTipText = Text
End With
On Error GoTo 0
End Function

Any ideas about the original question?

What's the problem with that code?
That was a response to Allen's question. Look at the whole thread and
it should make more sense.


Reply With Quote
  #3  
Old   
Andy
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-27-2003 , 07:10 AM



peter (AT) SunSpotCompDot (DOT) ComDot.Au (Peter Nurse) wrote in message news:<3efb731a.1264447 (AT) news (DOT) bigpond.com>...
Quote:
Allen, Allen,

I suspect we're going round in circles a bit. I posted
UpdateStatusBarControlTip() simply to demonstrate an instance in which
you might want to pass an object to a function.

Now, to ask the question again:-

In this example...
Sub MySub ()
With Forms("frmA").Controls("CtlA")
.Visible = True
.Enabled = True
UpdateStatusBarControlTip .Object
End With
End Sub

...is there a way I can pass the object Forms("frmA").Controls("CtlA")
to the function UpdateStatusBarControlTip() without repeating the
whole object definition.
Why is it a problem passing the object name?

Quote:
As I said in the original post..."Yes, I know I can simplify this by
using...
Set Ctl = Forms("frmA").Controls("CtlA")
...but that is sidestepping the issue."

Does that make it clear now?
Nope.

If a piece of code works with little overhead, then I don't see the
problem.
What problem are you trying to overcome.

You can pass Forms("frmA").Controls("CtlA") to a single (perhaps
wrapper) sub/function.
Then you only specify it once.
You could use controls(n) to refer to it, if you're bothered about the
overhead of resolving the name.
You could also use activecontrol.

But.
Why is set ctl = blaa no good to you?


Reply With Quote
  #4  
Old   
Allen Browne
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-29-2003 , 11:52 PM



Quote:
You can pass Forms("frmA").Controls("CtlA") ...

Should I conclude from your response that I can't pass the object to a
sub/function and we just need to find a way to work around it?
Peter, I can't understand what you are talking about either.

Passing
Forms("frmA").Controls("CtlA")
is not a workaround for passing an object. It *is* passing the object.

So all the properties of that object are available whereever you pass it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap"




Reply With Quote
  #5  
Old   
Peter Nurse
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-30-2003 , 04:55 AM



On Mon, 30 Jun 2003 04:52:33 GMT, "Allen Browne"
<abrowne1_SpamTrap (AT) bigpond (DOT) net.au> wrote:

Quote:
Peter, I can't understand what you are talking about either.

Passing
Forms("frmA").Controls("CtlA")
is not a workaround for passing an object. It *is* passing the object.

So all the properties of that object are available whereever you pass it.

Most (if not all) of the traffic in this thread has been way off the
origianl topic so...one last try after which I'll declare myself well
and truly defeated!

In the following code...

Sub A
Dim theDog as Dog


Reply With Quote
  #6  
Old   
David W. Fenton
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-30-2003 , 11:20 AM



peter (AT) SunSpotCompDot (DOT) ComDot.Au (Peter Nurse) wrote in
<3f0005e0.939686 (AT) news (DOT) bigpond.com>:

Quote:
Sub A
Dim theDog as Dog
.
.
Set theDog = ....
.
.
With theDog
.Visible=True
.Enabled = False
.
.
KillTheDog ????
End With
End Sub

Function KillTheDog (theDog as Dog)
.
.
.
End Function
KillTheDog theDog

Yes, within the WITH you have to repeat the reference.

But who gives a rat's ass?

If your question is:

Can the object on which a WITH is based be passed to an outside
subroutine using the WITH structure?

Then the answer is NO.

But why would it matter?

A WITH structure is for making code within a subroutine easier to
manage. It does not have applicability outside its own context.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc


Reply With Quote
  #7  
Old   
rkc
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-30-2003 , 07:35 PM




"Peter Nurse" <peter (AT) SunSpotCompDot (DOT) ComDot.Au> wrote

Quote:
Most (if not all) of the traffic in this thread has been way off the
origianl topic so...one last try after which I'll declare myself well
and truly defeated!
I understand your question. You want to know if there is a universal,
magical method that all Access and VBA Objects automatically have
that returns a reference to itself. Something like

Public Function ThisObject as (Object)
ThisObject = Me
End Function.

So you could

With theDog
.Color = YELLOW
.Rabies = True
KillTheDog .ThisObject
End With


Private Sub KillTheDog (dg as clsDog)
Call SobAndWeep
dg.Euthanize
Call BuryTheMutt
End Sub

The Object Browser says nope.






Reply With Quote
  #8  
Old   
Peter Nurse
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-30-2003 , 08:29 PM



On Tue, 01 Jul 2003 00:35:28 GMT, "rkc" <rkc (AT) rochester (DOT) rr.com> wrote:

Quote:
I understand your question. You want to know if there is a universal,
magical method that all Access and VBA Objects automatically have
that returns a reference to itself. Something like

Public Function ThisObject as (Object)
ThisObject = Me
End Function.

So you could

With theDog
.Color = YELLOW
.Rabies = True
KillTheDog .ThisObject
End With


Private Sub KillTheDog (dg as clsDog)
Call SobAndWeep
dg.Euthanize
Call BuryTheMutt
End Sub

The Object Browser says nope.
Hooray!! At last! Thank you also for your eloquent restatment of the
problem. I did suspect that there was no good solution...pity!


Reply With Quote
  #9  
Old   
Peter Nurse
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-30-2003 , 08:33 PM



On Mon, 30 Jun 2003 16:20:18 GMT, dXXXfenton (AT) bway (DOT) net (David W.
Fenton) wrote:
Quote:
Yes, within the WITH you have to repeat the reference.

But who gives a rat's ass?

If your question is:

Can the object on which a WITH is based be passed to an outside
subroutine using the WITH structure?

Then the answer is NO.

But why would it matter?

A WITH structure is for making code within a subroutine easier to
manage. It does not have applicability outside its own context.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

"Who gives a rat's ass? But why would it matter?" Well it didn't
justify the 14 or more posts - I thought I'd get the answer straight
away without all the confusion.

Thank you for understanding the issue.


Reply With Quote
  #10  
Old   
Peter Nurse
 
Posts: n/a

Default Re: Referring to the With . . . End With Object - 06-30-2003 , 08:36 PM



On 30 Jun 2003 06:09:14 -0700, aon14 (AT) lycos (DOT) co.uk (Andy) wrote:

Quote:
And yes.
It is possible.
You could write.

with ctl
.killthedog
end with

All you have to do is write a method yourself....
Oh.
Did I mention it wouldn't be easy?

with ctl
blaa
end with
killthedog(ctl)

Is easy enough and has no particular overhead.
So what's the problem?
Well, you've persisted and I thank you for that.

The problem has been solved (in the negative, as I suspected) in
another post from <rkc>.


Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.