Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2005

Tip: Looking for answers? Try searching our database.

Public Sub or Function to manage Control settings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brad - 27 Sep 2005 19:22 GMT
Thanks for taking the time to read my question.

I want to use labels for buttons instead of buttons. That way when the mouse
moves over the button, I can change its appearance.

That being said... instead of having code on all my label buttons, I'd like
to have a function or public sub that can take in the name of the control,
and adjust accordingly.  I can't seem to get this to work.  I can make it
work on the code for the form, but not in a public sub or function.

Here is what I have tried.

Click On The Label Button:
'Code on Form
Private Sub cmdOpenClientDatalbl_MouseDown()
  LBLToButtonDown ("cmdOpenClientDatalbl")
End Sub

'Code in Module
Function LBLToButtonDown(TheControlName As String)
Dim ctl As Control
With ctl(TheControlName)
   .SpecialEffect = 2
   .BackStyle = 1
End With
End Function

Any ideas on how I can affect the settings of a control on a form, from a
function or public sub by passing the name of the control.

Thanks,

Brad
Klatuu - 27 Sep 2005 19:28 GMT
You should use the buttons.  You can do the same thing with a command button.
Use the Mouse Move event.

> Thanks for taking the time to read my question.
>
[quoted text clipped - 29 lines]
>
> Brad
Brad - 27 Sep 2005 19:31 GMT
I understand, but you can't make a button "Flat" then on the Mouse Move make
it raised.

Brad

> You should use the buttons.  You can do the same thing with a command button.
>  Use the Mouse Move event.
[quoted text clipped - 32 lines]
> >
> > Brad
Klatuu - 27 Sep 2005 19:59 GMT
Then try using a toggle button instead.  Since a label has no events, you are
going to have a hard time making what you are trying to do work, if you can
at all.
Also, be more specific with your questions.  You did not say that in your
original post.

> I understand, but you can't make a button "Flat" then on the Mouse Move make
> it raised.
[quoted text clipped - 37 lines]
> > >
> > > Brad
Brad - 27 Sep 2005 20:12 GMT
Sorry I didn't mention that I want all my LabelButtons flat.

What I want is to have flat buttons, then when the user moves the mouse
over, the LabelButton becomes Raised, on Mouse Down, the LabelButton is
sunken, and on Mouse Up, the LabelButton returns to being raised. Moving the
mouse to the Detail section, makes all LabelButtons flat again.

I'm playing with this now.  How can I get variables into this command?

CODE:
Forms!TheFormName!TheControlName.SpecialEffect = 1

I can get this to work, but it is static
Forms!MainForm!LabelButton1.SpecialEffect = 1

I don't want to have to write out every single control.  I'd like to pass
the name of the control and form name and manipulate with one bit of code.

Thanks again for your help,

Brad

> Then try using a toggle button instead.  Since a label has no events, you are
> going to have a hard time making what you are trying to do work, if you can
[quoted text clipped - 43 lines]
> > > >
> > > > Brad
Klatuu - 27 Sep 2005 20:19 GMT
Look in the Object Browser for the Controls collection.  I think you will
find some useful info there.
Too bad command buttons don't have special effects.  It is leaving you with
some really hard work to get a simple visual effect.
BTW, had I read your code more closely, I could have figured out what you
wanted.  My apologies.

> Sorry I didn't mention that I want all my LabelButtons flat.
>
[quoted text clipped - 65 lines]
> > > > >
> > > > > Brad
Brad - 27 Sep 2005 20:26 GMT
I just found that as soon as I was notified that you had replied.

Here is the solution I found.

Thanks again for your help.

Brad

Solution:
Function LBLToButtonOver(TheFormName As String, TheControlName As String)
   Forms(TheFormName).Controls(TheControlName).SpecialEffect = 1
End Function

> Look in the Object Browser for the Controls collection.  I think you will
> find some useful info there.
[quoted text clipped - 72 lines]
> > > > > >
> > > > > > Brad
lwells - 27 Sep 2005 20:25 GMT
Brad,

This is what I use on my forms for label control like you are asking:

Function LabelMouseAction(action As String, i As Integer)
On Error GoTo Err_Handler

   Dim ctl As Control
   Dim strPrevious As String
       
   For Each ctl In Me.Form.Controls
       If (ctl.ControlType = acLabel And ctl.Tag = i) Then
               Select Case action
              Case "mousedown"
                   ctl.SpecialEffect = 2
              Case "mouseup"
           
              Case "mousemove"
                   ctl.SpecialEffect = 1
                   ctl.BackStyle = 1
               End Select
        Else
           With ctl
               .SpecialEffect = 0
               .BackStyle = 0
           End With
       End If
   Next
   
Exit_Handler:
   Exit Function
   
Err_Handler:
   MsgBox Err.Number & " " & Err.Description
   Resume Exit_Handler
               
End Function

Now for each label set the tag property to a number i.e.  1...2...etc for
each label you want the effect.  Then in the Mouse Move event for each label
call the function like so  
=LabelMouseAction("mousemove",1) for the first label
=LabelMouseAction("mousemove",2) for the second label and so forth

For the Mouse Down would be
=LabelMouseAction("mousedown",1) etc for each label on the mouse down

For the Detail section
=LabelMouseAction("mousemove",0)

This will make the label raised when the mouse is moved over the label and
appear sunken when you click down on the mouse.  When you move to the detail
section away from the label it will restore back to the flat appearance.

I also added a "mouseup" to the select case, but you can add any number of
select items you wish.

Hope this helps
lwells

> Sorry I didn't mention that I want all my LabelButtons flat.
>
[quoted text clipped - 65 lines]
> > > > >
> > > > > Brad
Brad - 27 Sep 2005 20:31 GMT
Wow!  That's awesome!

Thanks so much,

Have a great day,

Brad

> Brad,
>
[quoted text clipped - 125 lines]
> > > > > >
> > > > > > Brad
Dirk Goldgar - 27 Sep 2005 20:47 GMT
> Thanks for taking the time to read my question.
>
[quoted text clipped - 30 lines]
>
> Brad

Just pass a reference to the control itself, instead of its name:

   Function LBLToButtonDown(ctl As Access.Control)

       With ctl
           .SpecialEffect = 2
           .BackStyle = 1
       End With

   End Function

Your code to call the function then becomes:

   Private Sub cmdOpenClientDatalbl_MouseDown()
       LBLToButtonDown Me!cmdOpenClientDatalbl
   End Sub

Or you can just set the OnMouseDown event property to

   =LBLToButtonDown([cmdOpenClientDatalbl])

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Brad - 27 Sep 2005 21:01 GMT
Hey that's really neat too.

I don't understand why you don't need to put () around Me!cmdOpenClientDatalbl
in
   Private Sub cmdOpenClientDatalbl_MouseDown()
       LBLToButtonDown Me!cmdOpenClientDatalbl
   End Sub

Also, why is there an equals sign in your second option?  Does the equals
sign equal Call?(That sentence is almost like "Who's on First")

Brad

> > Thanks for taking the time to read my question.
> >
[quoted text clipped - 51 lines]
>
>     =LBLToButtonDown([cmdOpenClientDatalbl])
Dirk Goldgar - 27 Sep 2005 22:47 GMT
> Hey that's really neat too.
>
[quoted text clipped - 3 lines]
>         LBLToButtonDown Me!cmdOpenClientDatalbl
>     End Sub

This is one of the alternative methods of calling a procedure and
passing parameters.  You can use

   Call ProcedureName(parameter1, parameter2, ...)

or you can use

   ProcedureName parameter1, parameter2, ...

If you make a mistake, and write

   ProcedureName (parameter1)

you're actually forcing the evaluation of parameter1, before its value
is passed to the procedure.  This can cause problems sometimes;  it
would in this case, because we want to pass the control itself, not its
value.

> Also, why is there an equals sign in your second option?  Does the
> equals sign equal Call?(That sentence is almost like "Who's on First")

The equals sign there is the standard tag for an expression to be
evaluated in a control property;  in this case, the event property
OnMouseDown.  What I was talking about was not writing an event proedure
for the button's MouseDown event, but putting that function expression
into the OnMouseDown event property itself, just as you might put a
function expression in the ControlSource property of a calculated
control.  This is a trick that Access supports.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Marshall Barton - 27 Sep 2005 21:46 GMT
>Thanks for taking the time to read my question.
>
[quoted text clipped - 25 lines]
>Any ideas on how I can affect the settings of a control on a form, from a
>function or public sub by passing the name of the control.

The With statement is out of whack. Your problem is in
referring to the control on different forms by just passing
the name of the controls.  The with statement should be:
    With Me(TheControlName)

But this will only work if the code is in the form's module,
which may be all you need in this case.  If you want to
create a more general function, then it is better is to pass
the control object itself:

'Code on Form
Private Sub cmdOpenClientDatalbl_MouseDown()
  LBLToButtonDown (Me.cmdOpenClientDatalbl)
End Sub

'Code in Module
Function LBLToButtonDown(TheControl As Control)
With TheControl
   .SpecialEffect = 2
   .BackStyle = 1
End With
End Function

This way the function can be in any module and it is not
tied to any one form.

Signature

Marsh
MVP [MS Access]

Dirk Goldgar - 27 Sep 2005 22:48 GMT
>> Thanks for taking the time to read my question.
>>
[quoted text clipped - 41 lines]
>    LBLToButtonDown (Me.cmdOpenClientDatalbl)
> End Sub

While we're in agreement on the approach, Marsh, the parentheses in that
call will cause the value of the control to be passed, not the control
itself.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Marshall Barton - 27 Sep 2005 23:45 GMT
>> Brad wrote:
>>
[quoted text clipped - 47 lines]
>call will cause the value of the control to be passed, not the control
>itself.

Yes, of course.  I going to go right now and make that darn
parenthesis gremlin promise to never do that again or he'll
sit in the corner all night    ;-)

Signature

Marsh
MVP [MS Access]

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.