Base macro to restore focus to a form field

I have a Base form that runs a macro when the value is entered, but then the focus shifts to the next tab stop. How can I make the focus return to the control again?

1 Like
'Get Form'
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
'Get Field'
    oField = oForm.getByName("txtMyControl")
'Get field VIEW'
    CtlView = ThisComponent.getCurrentController().getControl(oField)
'Set Focus'
	CtlView.setFocus()
1 Like

I tried adding this code to the end of my macro, got "BASIC run time error. Variable not defined."

oForm = ThisComponent.Drawpage.Forms.getByName(“Form1”)

1 Like

If you have Option Explicit set you must Dim the variables.

thanks, that works!