Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

workaround for enter before click event

Status
Not open for further replies.

projection

Programmer
Aug 24, 2004
12
US
Hi Tek-tips,

I came across an interesting design issue with a textbox on an access 2k form. When the user CLICKS the textbox, the File_Enter() event happens, which has a call to a function to prompt the user with an open file dialog. Once the user selects a file, the textbox is populated with a hyperlink to the file. This is all good except that the click event is triggered after the Enter event and the file is opened by its native viewer. I would rather this not happen. So, I ask you, how do I cancel the opening of the file? I have tried docmd.cancelEvent with no real effectiveness. Perhaps I was doing something wrong.

If anyone knows how to manage and cancel events that happen, please help me. I will post code if need be.

Thank you so much in advance!
 
How are ya projection . . .

Why not use the [blue]On Dbl Click[/blue] event instead!

As your code currently stands, you could [blue]set a boolean variable to indicate the [purple]OnEnter[/purple] event was triggered[/blue] and look at this variable in the [purple]OnClick[/purple] event, [purple]but you have no way of knowing if the OnEnter event was triggered by tabbing into or clicking the textbox![/purple]

Calvin.gif
See Ya! . . . . . .
 
Hi AceMan1,

Thanks for your response. I agree. There is no way of knowing how the onEnter event happened so it is best to have the flag in that event. That is what I have. The function to create the hyperlink also contains a global flag that is set to false when created otherwise it is set to true.

In the onclick event, I have a simple condition that if the flag is false then perform the docmd.cancelevent. When I step through the code, the file does not open. However, when I take away the breaks, the file opens after the hyperlink is created.

The more I play with the code, the more I feel like I am not looking at the right spot. Is there any way to see the stack of events to understand exactly where the trigger to open the file is? Or is there another command to stop the opening of the file?

I will post code if need be. Thank you for reading!
 
projection . . .

Instead of setting an actual hyperlink ([blue]were talking changing the field to Text[/blue]), just enter the data as text, and in your [blue]OnClick[/blue] event use the [blue]FollowHyperLink[/blue] method . . . to set the link in motion . . .

Your Thoughts?

Calvin.gif
See Ya! . . . . . .
 
Hi AceMan1,

Nice suggestion/alternative. I will implement this instead. That way I have more control over what is happening. I will let you know how it goes.

Thank you so much for your help!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top