473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How do I make the subform the active control when the mouse moves over it?

Seth Schrock
2,965 Expert 2GB
I've got a form that has a subform on it. Currently, in order to scroll in the subfomr with the mouse wheel, I have to click somewhere in the subform. I would like to be able to be able to have it be selected when the mouse moves over it so that I don't have to click. I've looked at the subform events, but the only two listed are On_Enter and On_Exit. I tried looking at the events of the subform as a form and not as a subform and the only one that makes sense is On_Mouse_Move. The only problem is that I don't know how to check if the mouse is moving over the subform or the regular form.

Is this possible?
Feb 8 '12 #1

✓ answered by Mihail

@ADezii
Correct me, please if I am wrong.
I think that in boolean logic your counter act the same way as a boolean variable: Your counter IS or IS_NOT = 1.

@Seth
Your code can't work (either if you use a boolean variable or a counter one) because you initialize SubFormHasFocus inside the event procedure (line 2). And the default value is FALSE.
So, the IF statement will be executed every time your mouse is moving.
Line 8 has no effect. You can remove it :). That because when you exit from procedure (line 10) all variables declared inside the procedure using Dim statement are complete removed from memory.
If you wish to keep a value for a variable between calling you must use the Static statement. Simple replace DIM with STATIC.

In my first post I say to define the boolean variable at MODULE level.
Also your line 8 must be moved between line 5 and 6.

Any way, I prepare an example (see attachment) with a possible approach to solve your original question:
How do I make the subform the active control when the mouse moves over it?

Hope this is a help for you.
Good luck !

17 4785
ADezii
8,834 Expert 8TB
Try the MouseMove() Event in the Detail Section of the SubForm.
Feb 8 '12 #2
Seth Schrock
2,965 Expert 2GB
Okay, I put the following in the MouseMove() event like you said.
Expand|Select|Wrap|Line Numbers
  1. Me.Parent![Returned Mail Subform].SetFocus
The only problem is that as long as the mouse is over the detail section (it doesn't have to be moving), it keeps running over and over. Is there a way to keep it from getting triggered when the mouse isn't moving?
Feb 8 '12 #3
NeoPa
32,556 Expert Mod 16PB
I find your explanation very confusing Seth. Can you post the code (including all relevant lines, such as the procedure wrappers, etc).
Feb 8 '12 #4
Mihail
759 512MB
Define a boolean variable at the module level
Expand|Select|Wrap|Line Numbers
  1. Dim SubFormHasFocus As Boolean
Set it to TRUE after the sub-form recive focus and run your code only if this variable is FALSE.
When the sub-form lose focus set the variable to FALSE.
Feb 9 '12 #5
Seth Schrock
2,965 Expert 2GB
I didn't get a chance to work on it today. I'll post more tomorrow.
Feb 9 '12 #6
NeoPa
32,556 Expert Mod 16PB
No worries Seth. I'm out most of tomorrow but I'll catch up when I'm around certainly.
Feb 10 '12 #7
Seth Schrock
2,965 Expert 2GB
@NeoPa, Here is the code. It is in the subform's Detail on mouse move event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2. Me.Parent![Returned Mail Subform].SetFocus
  3. End Sub
  4.  
@Mihail, Here is the code that I tried per your idea:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2. Dim SubFormHasFocus As Boolean
  3.  
  4. If SubFormHasFocus = False Then
  5.     Me.Parent![Returned Mail Subform].SetFocus
  6. End If
  7.  
  8. SubFormHasFocus = True
  9.  
  10. End Sub
However, the screen keeps cycling whenever the the mouse is over the detail section. If I put my mouse over a control, it stops. I'm also concerned about performance since this is the main screen used. This code will be run over and over even if we get the SetFocus problem fixed. Is there an event that runs when the mouse first moves over the subform instead of it running all the time the mouse is over the subform?
Feb 10 '12 #8
ADezii
8,834 Expert 8TB
Instead of a BOOLEAN, try a Counter (LONG). Increment the Counter by +1 whenever the Mouse moves acccross the Detail Section of the Sub-Form. Only set the Focus to the Sub-Form when the Value of the Counter = 1, then Reset the Counter to 0 when the Mouse moves to the Main Form.
Feb 10 '12 #9
Mihail
759 512MB
@ADezii
Correct me, please if I am wrong.
I think that in boolean logic your counter act the same way as a boolean variable: Your counter IS or IS_NOT = 1.

@Seth
Your code can't work (either if you use a boolean variable or a counter one) because you initialize SubFormHasFocus inside the event procedure (line 2). And the default value is FALSE.
So, the IF statement will be executed every time your mouse is moving.
Line 8 has no effect. You can remove it :). That because when you exit from procedure (line 10) all variables declared inside the procedure using Dim statement are complete removed from memory.
If you wish to keep a value for a variable between calling you must use the Static statement. Simple replace DIM with STATIC.

In my first post I say to define the boolean variable at MODULE level.
Also your line 8 must be moved between line 5 and 6.

Any way, I prepare an example (see attachment) with a possible approach to solve your original question:
How do I make the subform the active control when the mouse moves over it?

Hope this is a help for you.
Good luck !
Attached Files
File Type: zip SubFormSetFocus.zip (27.3 KB, 196 views)
Feb 10 '12 #10
Seth Schrock
2,965 Expert 2GB
That is exactly what I need.

I totally missed the at module level. I'll admit, I'm not very good with VBA. I have a book that would teach me if I read it, but I just don't have the time:) I've learned a lot through this forum, but I wish I new more. I'm basically learning the stuff that I need and then I print out the code so that I can use it next time with the proper adjustments.
Feb 10 '12 #11
Seth Schrock
2,965 Expert 2GB
I just put the label around my subform and did the OnMouseMove event. What I don't get is that on my database, when my mouse is over the label, the code is constantly running even when the mouse is not moving. In your sample it doesn't run unless the mouse is moving and only once every half inch of movement. Any ideas? I'm using Access 2010.
Feb 10 '12 #12
Mihail
759 512MB
And where is the problem ? Hope you had removing the BEEP statement from my code. It is not necessary. So the code can run in silence how long your mouse is over the label.

If this is a really problem for you, let me know and I am sure that can be solved. But please tell me what trouble you have if the code is running when your mouse is over the label.
Feb 10 '12 #13
Seth Schrock
2,965 Expert 2GB
The problem is that the screen flashes at about 5 flashes per second. Admittedly, there is only a little area on the screen where the mouse can be where it will do this. The code works fine in that the subform is selected. Your sample works perfectly without the flashing. I just don't know why mine works differently from yours. I did remove the beep portion of the code. I'm no longer at work, so I don't have access to the code until Monday.
Feb 10 '12 #14
Mihail
759 512MB
I think my code also flash but is a little bit to screen refresh so it is not visible that flash.
Ok. I'll see until Monday how can be improved.

Have a nice week-end !
Feb 10 '12 #15
Mihail
759 512MB
Replace the code in MY database with this one:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Label_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     If Not (ActiveControl.Name = "Subform") Then
  3.         Beep
  4.         Subform.SetFocus
  5.         Txt = "The Subform HAS focus. Click the command button."
  6.     End If
  7. End Sub
then adapt for you.
Feb 10 '12 #16
Seth Schrock
2,965 Expert 2GB
I forgot that I needed to test out your code! Anyway, I just tried it on yours and it didn't flash. I adapted it for my database and it flashed. So I decided to do a test and commented out all of the code and it still flashed. Another thing that I noticed is that the VBA editor says that mine is constantly running whereas yours does not. So I think that it has something to do with my database. Thanks for your help.
Feb 15 '12 #17
Mihail
759 512MB
Hm.
Try to copy-paste MY label from MY form into your form.
Or import MY form in your database and work with it.

I can't see any reason for your trouble.
Sorry.
Feb 15 '12 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Mr B | last post by:
Howdy, I want to set up an Include page in a cell of a table. Then I want to be able to change which page is included on the fly as the user moves the mouse of the various links on the page. ...
3
by: Robert Neville | last post by:
How do you return the last Active Control when the control is on a tab control? Screen.ActiveControl does not seem to work. Here's the statement that my code uses. Set ctlOld =...
5
by: Martha | last post by:
When I move my mouse over a hyperlink component, the hyperlink does not change color. How do I change the color of a hyperlink when the mouse goes over the hyperlink? or Change the color of a...
5
by: Manuel Daponte | last post by:
I found this code in this newsgroup and used it, but the lines drawn are composed of point too separated when the mouse moves at medium or fast speed. How can I fix it? Thanks in advance !!! ...
4
by: MLH | last post by:
Short of inserting code similar to that shown below in the OnGotFocus event property for each and every control on the form, is there a form-level event I could monitor firing similar code. I...
4
by: cb.brite | last post by:
Hello, I have tried this using the MouseEnter/MouseLeave events. However these events do not really refer to the rectangular shape of the form, but the client area (form area minus children...
1
by: google | last post by:
I have a form with several subforms. Users enter the data, then on the parent there is a command button that runs code to generate a .pdf document from a report based on the data they are working...
1
by: sharma1985 | last post by:
Hi all, I m worhing on creating an user intractive scatter graph images which contains thousands of points on it. So,I would like to know that how could i display the coordinates of every...
5
by: kimiraikkonen | last post by:
Hi, I couldn't find a necessary class which shows when mouse hovers on a link in Webbrowser control. Think of there's a status bar(text), when mouse comes on a link, the URL must be shown in...
4
by: Spencer Killen | last post by:
As the title says i'd like to have a image (mocha1150.Gif) and when the mouse moves over them id like them to change to mocha5150ani.Gif and when the mouse moves out id like to change it back to...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.