Subform Datasheet Focus Problem

zooropa66

Registered User.
Local time
Today, 17:36
Joined
Nov 23, 2010
Messages
61
I have a subform datasheet that defaults to the first TabIndex field so the text is highlighted. Is there a way to remove focus from all my subform controls (they are all text/label pairs) or some trick workaround similar to setting focus to a transparent button (which isn't an option on a form in datasheet mode)

Thanks
 
Not really, in Datasheet View. If your object is to simply not have the Control highlighted, you can go to Tools - Options - Keyboard and set the Behavior Entering Field to Go to Start of Field or Go to End of Field, instead of its current Select Entire Field setting.

Of course this would have to be done on all PCs running the app, and some users may object. I despise this setting as it makes it all too easy to accidentally delete the data.

A workaround would be to use code like this to deselect the Control on entering it. Replacing ControlName with the actual name of your Textbox,
Code:
Private Sub ControlName_GotFocus()
 ControlName.SelLength = 0
End Sub
Linq ;0)>
 
Hi Linq,
Thanks for your reply. I tried the selLength suggestion but all it does is put the cursor to the far left of the text box (as opposed to the whole of the text field being highlighted)

Is Access really so clunky that you can't easily choose not to have a field highlighted on a datasheet?

Does anyone have any other suggestions for how to lose focus from a subform datasheet (sorry if my terminology isn't quite right)

Thanks
 
Hi Linq,
Thanks for your reply. I tried the selLength suggestion but all it does is put the cursor to the far left of the text box (as opposed to the whole of the text field being highlighted)
Are you saying that the cursor moves to the left of the Control but that it stays highlighted, using the code I gave you?

Linq ;0)>
 
Hi Linq, Sorry for the delayed reply but i seem to have missed your reply. The cursor moves to the left of whatever's in the field with the lowest Tab Index and isn't highlighted. It looks better but you still have a blinking cursor. I just want the subform to appear as a datasheet, no cursor, no highlighting. It would be easy if the subform wasn't in datasheet mode as i could just setfocus to a transparent button. arrgh!
 
Yes, as i won't be editing any info presented in that datasheet. The first field that is highlighted is a hyperlink and the other fields are just straight text and number fields.
 
Not sure about the Hyperlink (do you want to be able to click on it?) but to prevent the Subform from getting Focus, which is to say to make it Read-Only, in Design View for the Main Form, select the Subform Control (the Control itself) and go to Properties - Data and set

Enabled = No

Locked = Yes

Linq ;0)>
 
Hi Linq, That worked but then the subform scrollbars lock up. Nice one Microsoft for making what should be easy nigh on impossible.
 
Highlight all the controls > set the Locked property to Yes > set the Enabled property to No.
 
I never did get a satisfactory answer to this question.

The conclusion i reached is that only controls that are useable in the datasheet e.g. textboxes can be set visible and can therefore receive focus. Furthermore, the focus must be set to at least one of these useable controls (the one with the lowest tabindex)

I have seen posts whereby you can mimic a datasheet form using a continuous form. This would then allow you to set focus to a transparent command button.

Would anyone care to comment on the accuracy of my conclusion?

Thanks :confused:
 
Last edited:
I gave you a solution in my last post. How did that not solve your problem?
 
Hi vbaInet, Thanks for your reply. I did try your suggestion but what i forgot to say was that one of the fields in the datasheet is a hyperlink and so i couldn't set it enabled=no (if i did then the hyperlink wouldn't work) Since this field has enabled=yes, it would assume focus. Sorry for not replying to your earlier post - it was remiss of me - my poor excuse is that i just gave up on finding a solution to this and generally lost the will to live (from a programming point of view)
 
Last edited:
What about the attached?

Also, moving forward, please give as much information as is necessary.
 

Attachments

Hi vbaInet,
Thanks for your help. It's much appreciated.

I hope you don't mind me altering your file slightly so it's more similar to the situation i'm faced with (see attached).

When i click one of the hyperlinks, i display a MsgBox with the value of the Hyperlink field (in my real application i switch to another page on a Tab Control who's content depends on the hyperlink i've just clicked on)

The problem is that it stays highlighted - it doesn't seem to remove focus onto the zero width txtFocus textbox on your main form.
 

Attachments

Last edited:
You didn't use all of what I gave you in the db. The following line is needed:
Code:
Me.txtWebsite.SelStart = 0
Look at the db and you will find where it was put.
 
Hi vbaNet,
Perfect!

That's exactly what i wanted.

For anyone else who might be as clueless as me, place the following 2 lines of code in the Click even for the subform textbox (which i've called txtsubform here). This textbox has its hyperlink property set to Yes.

Code:
Me.txtsubform.SelStart = 0
Me.Parent.txtFocus.SetFocus

After clicking txtsubform the focus will be moved to another textbox on the main form (called txtFocus). You can then add code to do whatever you want after it.

Once again, thankyou so much vbaInet. You stuck by me and i got there in the end.
 

Users who are viewing this thread

Back
Top Bottom