vb123.com

Garry Robinson's Popular MS Access, Office and VB Resource Site

 

Home  Contact Us
Order our Software

RSS & Newsletter  
Join our XML/RSS Newsfeed or sign up for our informative newsletter on Office Automation, Access and VB topics
Read More

Get Good Help
If you need help with a database, our Professionals could be the answer
Read More

  Is Your Database Corrupt ?
If you have a corrupt database, Try our Access Recovery service

The Workbench  Find out who has your database open, start the correct version of Access, easy compacting and backups, change startup options, mde compile,  shutdown database Read and Download

The Toolshed 
Searchable help file comprising of all the information at vb123.com plus hidden downloads etc. Read More



The Toolbox

Libraries of software that we regularly import into our projects. Enhances the Toolshed More..


DryToast New
Backup and query your BaseCamp
® projects
Read More


Datamining/Graphs

Explore your data with this versatile graphing and data mining shareware tool. 
Read More

Garry's Blog
Find out a few other things that Garry has been writing about Microsoft Access. Read more

About The Editor Garry Robinson writes for a number of popular computer magazines, is now a book author and has worked on 100+ Access databases. He is based in Sydney, Australia
Contact Us ...

Search ...

or try our Aussie
 vb123.com.au
  mirror site

 

Next Tip  Access Pizaz - Mouse Move and Mouse Hover Methods

by Garry Robinson - www.gr-fx.com

Add some Explorer like functionality to your command buttons using the following on MouseMove event.  CmdOpenForm is an example button on an form.  

Private Sub CmdOpenForm_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)


  On Error Resume Next
  CmdOpenForm.SetFocus
End Sub

Only ever use this on your main forms and never use it on any forms where you are managing data as it will cause the update record event to occur.  You can be more sophisticated by putting a toggle switch in the code so that focus is only set once and is turned off when the command button looses focus.

Mouse Hover - Alternative Method For Forms With Records 

By Terry Bell from Victoria in Australia  tbell @ netspace.net.au

Here's some code that highlights command buttons as you go over them with the mouse (by making them change colour).  It's a bit like several other snippets I've seen that use OnMouseMove to change the visual properties of controls.  You can extend this function to cover other controls such as text boxes, and it looks quite effective.  The problem is, as soon as you put a datasheet subform on your main form, you can't extend the effects to the datasheet.  So everything looks fine until you move the mouse over the datasheet, then nothing happens until you move the mouse out again.  Anyway, I decided I didn't want to burden my users with that inconsistency, so I've just left it with the command buttons.
 
It works well and it's surprising how quickly you become dependent on the
effect to help you know where the mouse is.  It doesn't force any updates, and you implement it for the whole form with a single line of code in the form's load event.

Step 1  Open up a new module in the database container and copy this code in full to that module and save it.  

'
''''''''''''''''''''''''''''''''''''''
' Original coding by Terry Bell '
' Bellco (Vic) Pty Ltd '
' 8 Dreadnought St '
' Sandringham Vic 3191 '
' Australia '
' 061 3 9598 4453 '
' Email: tbell at the following ISP '
' netspace.net.au '
''''''''''''''''''''''''''''''''''''''

Function gSetupCmdHighlights(frm As Form)

Dim cntl As Control, Sctn As Section, i As Integer

'Set the OnMouseMove event for all Command Buttons to function gMouseMove
'Set the OnMouseMove events for all non-Command button controls to function gClearCmdHighlights

For Each cntl In frm.Controls
  Select Case cntl.ControlType
    Case acCommandButton
      cntl.OnMouseMove = "=gMouseMove(""" & frm.Name & """," & cntl.Name & ")"

    Case 112 'Subform has different syntax (".Form.") shown below _
      cntl.Form.OnMouseMove = "=gClearCmdHighlights(""" & frm.Name & """)"

    Case Else
       On Error Resume Next
       cntl.OnMouseMove = "=gClearCmdHighlights(""" & frm.Name & """)"
       On Error GoTo 0
  End Select
  Next

'If the mouse moves over a different report section, switch any highlight off

  On Error Resume Next
  For i = 0 To 4
    frm.Section(i).OnMouseMove = "=gClearCmdHighlights(""" & _
    frm.Name &   """)"
  Next

  On Error GoTo 0
End Function

Function gMouseMove(frm, CtlName As Control)

'You only get here from OnMouseMove events that happen over command buttons
'If the command button is not already highlighted (in blue), 
'the current fore color is saved in the tag property of the button
'and the colour is set to blue
'Then any other command buttons on the form are checked and if they 
' are highlighted they are switched off.
'The second for each caters for the situation where you have two immediately adjacent command buttons with no 'intervening other form controls which would otherwise take care of switching off the highlighting
'on the command button being vacated.
'On the line marked *** you can experiment with different colours

Dim cntl As Control, fm As Form
Set fm = Forms(frm)
On Error Resume Next
If CtlName.ControlType = acCommandButton And CtlName.Tag = "" Then
  CtlName.Tag = CtlName.ForeColor 'Save original forecolor
  CtlName.ForeColor = vbBlue '***
End If

For Each cntl In fm.Controls
  If cntl.ControlType = acCommandButton And _ 
   CtlName.Name <> cntl.Name And cntl.Tag <> "" Then
    
    cntl.ForeColor = cntl.Tag
    cntl.Tag = ""
  End If
Next

On Error GoTo 0
Set fm = Nothing
End Function

Function gClearCmdHighlights(frm)

'This clears the highlights on all command buttons in the form
'and restores the original forecolors that were saved in the Tag properties

Dim cntl As Control, fm As Form
Set fm = Forms(frm)
For Each cntl In fm.Controls
  If cntl.ControlType = acCommandButton And cntl.Tag <> "" Then
    cntl.ForeColor = cntl.Tag
    cntl.Tag = ""
  End If
Next
Set fm = Nothing

End Function

Step 2  Add this code to the form that you want the mouse hovers on

To activate Command button highlighting, add the following to the load event of your Access form:

Private Sub Form_Load()
' Highlight command buttons as the mouse hovers over them

  gSetupCmdHighlights Me
End Sub

 

Scheduling Of Access Tasks

Click here to find out how to run multiple access actions overnight using the scheduling capabilities in Graf-FX.   These actions include Macros, Printing and Queries

 

 

Links >>>  Home | Search | Workbench | Orders | Newsletter | Access Security | Access professionals