Solved Text box with function to return text does not display on form until enabled (1 Viewer)

GaP42

Active member
Local time
Tomorrow, 07:12
Joined
Apr 27, 2020
Messages
338
I have a Textbox (Auto_Header0) in the header of a search form to display the name of the organisation and concatenated text. The name of the organisation is retrieved by a function. The control source for the text box is : =fMainOrg("FullName")+" Search"
Unless I (temporarily) set the focus to this control using the on load event for the form it does not display. It displays correctly when enabled on load by including the following 2 lines of code:
Me.Auto_Header0.SetFocus ' Needs focus to display
Me.Auto_Header0.Enabled = False ' Turn off as should not be editable
However this is not satisfactory: If I move to different form, the Textbox on this form no longer shows the text. Returning focus back to this form, the text box does not display any text.
To overcome this I have tried using the onActivate event, and the GotFocus event to set focus, enable and the then (dis)enable the text box to force it to display the expected text. These did not resolve the situation. onActivate only works following onLoad so is not triggered again, GotFocus had no effect. So tried OnCurrent:

The search form is used to open a form for a specific selected record - when any of these are closed a requery of this search form (to show any updates in the search list) occurs. If I use the OnCurrent Event to enable/setfocus and then disable the text box it displays the content of the text box but has the unintended consequence that :
1. The text box "flashes" as it is enabled/disabled when the user selects a record form the list of search results (to launch a form)
2. it requires two clicks instead of the expected one, when the user selects the searched for record to open the form (ie to the user it appears not to respond on the first click) - because the OnCurrent occurs as you move to a new record - and selecting a record in the search fires this event.

Is there a way around this - apart from closing the search form and reloading it - instead of a requery?
And is this normal behaviour for a text box with a control source using a function ? The same form has a call to a function for an image control that works fine, so it is strange.
BTW using Access 2010
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:12
Joined
May 7, 2009
Messages
19,245
you have disabled the control so it will not refresh.
another Event you might want to move your code is on the Activate event of the form.

private sub form_activate()
with Me.Auto_Header0
.enabled = True
.requery
.enabled=false
end with
end sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:12
Joined
May 7, 2009
Messages
19,245
you can always Enable the textbox, and prevent it
from getting Focus by moving to another textbox/combobox on the Form.
the following code assumes that the Enabled Property of the Auto_Header textbox is set to True
and it's "Tab Stop" property to No.

private sub form_activate()
Me!Auto_Header.Requery
end sub

private sub Auto_Header_GotFocus()
'focus on another control
Me.TextboxName.SetFocus
end sub

we are not switching it's enabled property (on/off), therefore minimizes the "flashing".
 

GaP42

Active member
Local time
Tomorrow, 07:12
Joined
Apr 27, 2020
Messages
338
Thanks arnelgp. I had used the sequence enable, getfocus (dis)enable for the control, and it was enabled on load. I then used your suggestion re the OnActivate, using requery instead of setfocus. Initially this did not appear to work - the value did not appear in the text box when I opened a different form and then returned to this one. I saw the advice from Miscrosoft "The Activate event doesn't occur when a form receives focus back from a dialog box, popup, or another form. " and thought this may be issue. However, considering the "strange" behaviour of this con trol (and knowing others elsewhere in the app were working without this problem) I decided to close down Access and re-open (keeping your suggestion for on activate) .. and then it worked. Thanks again

PS.. I was moving the focus to the search box after dealing with the Auto_Header text box :)
 

Users who are viewing this thread

Top Bottom