Control in question?

CJBIRKIN

Drink!
Local time
Today, 09:37
Joined
May 10, 2002
Messages
255
Hi

Does anyone know if there's a way of determining what control the cursor is currently over without using any of the events of the control itself.

--more details--

What i have is a help file that is a form with the background set to a picture of part of a complex paper form.

The user is able to select a command button which changes the cursor to a ? mark. When this is clicked on an entry form object the help form is displayed with an arrow pointing to the position on the paper form where the data can be found. At present the events are fired from the object. i.e

Code:
Private Sub names_click()
If GETCURSORSTYLING = 112 Then
MODULE_HELP.HELPFILE Me.Names.Tag
End If
End Sub

I have nearly 100 pieces of data to enter and consequently many objects. If i could use an event at form level to determine the control being interrogated i could dramatically reduce the amount of code.

Any clues?

Thanks

Chris
 
You could use an image map type approach by using the form's mouse move event ie

Code:
Option Explicit
Public X_loc as Integer, Y_loc as Integer
-----------------------------------------------------

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
X_loc = X
Y_loc = Y
End Sub

Sub Form_Click()
Dim strHelpfile as string
strHelpfile = Dlookup("HelpfileName","tblHelpfiles" "[Xloc] = " & X_loc and "[YLoc] =  " & Y_loc)
If GETCURSORSTYLING = 112 Then
MODULE_HELP.HELPFILE strHelpfile
End If

This unfortunately means having a table logging the exact data of the co-ordinates to interrogate and even having a spread of X_Start, X_end, Y_Start and Y_End

The example code I gave should work for an exact value but you will need to tweak it to capture the full spread ie >=X_Start and <=X_End etc....

Other than that I don't think you can do it.
 
Hi


Thanks for the help, unfortunatley Rich there does not appear to be a .name method for activeobject and when i tried the same thing for the activeform.name, as a test, i got an error saying

"you entered an expression that requires a form to be the active window" what ever the hell that means!:confused:

Fizzio, i can see how your approach works but I reckon it would take me just as long to get the data as write the code for each object.

Thanks for your efforts. :D


Chris
 
Yep I agree with the workload thing - You didn't say an easy solution!

(edit) Actually, getting the data would not be that difficult, just set up two temporary textboxes and on the Form_Mousemove event, update the textbox value with the mouse coordinates - go back to good old pen and paper - write down the values thrown up then plug these into a table - I reckon this would actually be quicker than programming each control separately.(/edit)

The screen.activecontrol will only work if the control has the focus ie selected, not when it is hovered over.
 
Last edited:
Hi

Not easy indeed! :D. I actually did this for the help files, or rather i created a table to store the x and y coords where i want the arrow positioning and then did
Code:
Public Function createhelp(XAxisVal As Single, YAxisVal As Single, FrmName As String)
Dim Db As DAO.Database
Dim Rst As DAO.Recordset
Set Db = CurrentDb
Set Rst = Db.OpenRecordset("Select Tbl_Help.* from Tbl_Help;")

Rst.AddNew

Rst![Xaxis] = XAxisVal
Rst![Yaxis] = YAxisVal
Rst![FORMNAME] = FrmName
Rst.Update


Set Rst = Nothing
Set Db = Nothing


End Function

called from the forms detail mousedown event.

What happens is when i run my help function it takes the value i entered in the tag of the control and finds the corresponding record in the table, it returns the formname (there a 4 help forms) and the co-ords and then creates a copy of the form and places a picture of an arrow on it at the correct coordinates.

I can forsee that there could be problems if the users have different screen resolutions with this and the same if i use your map technique.

As for the screen.activecontrol it will only return the value of the data in the control and not the controls name, and as you say the control needs the focus. That in itself is not the problem as i expected the users to click on the control but this will not fire any form events so i am stuffed anyway!

Thanks for trying

Chris
 
Nice solution that - better than the pen and paper option I suggested!
I know what you mean by the screen resolution

Next challenge then - get the screen resolution and create 2 tables!

there is a GetResolution function hidden somewhere in here by GHudson:p
 
Hi Fizzio

Even if i did the map i still wouldn't have an event to fire it from, if i use any of the forms events they aren't called unless you interact with the form. As soon as the cursor is over a control the form events (at least the click and mousedown ones) won't do anything.

Thanks for the screen res link i remember using that somewhere before, i'll have to dig it out.

Anway I'm off home to think about it. If i have a 3am flash of inspiration i'll let you know tommorrow!

Cheers

Chris:p
 
Bugger, all that fancy coding and co-ordinates idea for nowt.

Hmmm - I shall too report back if I get a 3am inspiration!

Kristin
 
CJBIRKIN said:
Hi


Thanks for the help, unfortunatley Rich there does not appear to be a .name method for activeobject and when i tried the same thing for the activeform.name, as a test, i got an error saying

"you entered an expression that requires a form to be the active window" what ever the hell that means!:confused:

Fizzio, i can see how your approach works but I reckon it would take me just as long to get the data as write the code for each object.

Thanks for your efforts. :D


Chris
Sorry, I could have sworn it read that users had to click an object on the form and you wanted to return the object name,
ie: control.
must have read it wrong:mad:
 
I see your point Rich but it would still require coding each control - it cannot be done at form level - as Chris has found with the elaborate Idea we coem up with - bugger :mad:
 
See, I've told them the treatment isn't working:mad:
it should of course have been Screen.PreviousControl.
And I'm going to demand my money back:rolleyes:
 
Hi

No 3am inspiration.


Rich you are right, in that i wanted to return the controls name. Up to now i just used the click event of the control, as Kristin points out i wanted to do this at form level i.e have an form event fire after the user clicks on the control that returns the name of the control to a function which creates the help file. I can't find a form event that fires after the click event of the control so i'm stuffed as far as that ideas concerned.

Thanks for trying

Chris

...... NEWS FLASH

I think i see what your getting at, at present the user clicks the cmd button that changes the pointer to a ? mark. They then move the ? mark over the control on the form and click. If i just let them set the focus to the control they are interested in and the press the ? mark button it would be able to to do screen.previouscontol.name (odd that name doesn't appear in my list of methods after i enter the ".").

.......NEWS FLASH

This works but as i have subforms i need a ?mark button on each of the subforms. If i use it on the main form all i get is the name of the subform. Still i like this better than the way i was doing it.
If you know of a way round this i would be v.interested.

Thanks for all your help

9am inspiration !!
Chris
 
I'm sure there's a way around it, but I can't think of one at the minute, a sub form's just a control on the main form of course.
You could use linked forms
 

Users who are viewing this thread

Back
Top Bottom