开发者

Can focus be remove from a control to modify its properties in VBA?

开发者 https://www.devze.com 2023-01-23 19:01 出处:网络
First I remove control visibility by doing this: For Each ctl In Me.MySubform.Controls ctl.Visible = False

First I remove control visibility by doing this:

For Each ctl In Me.MySubform.Controls
    ctl.Visible = False
Next ctl

and later, I go back and bind those controls I'm going to use for the current list of fields using an array of the caption and control source name.

For i = 0 To UBound(MyArray) Step 2
    Me.MySubform.Controls(i).ControlSource = MyArray(i)
    Me.MySubform.Controls(i + 1).Caption = MyArray(i + 1)
    Me.MySubform.Controls(i).Visible = True
    Me.MySubform.Controls(i + 1).Visible = True
Next i

The issue I run into is, if a user has clicked into one of these fields providing it with focus, I seem to set the control visible property to false or rebind the field to another field during the next refresh event.

I think by removing the controls focus I would be able to accomplish this; however, I have two concerns.

  1. Is this possible in VBA (MS Access 2003)? If so how?
  2. Is there a better more ideal way to accomplish this in this environment? If so, what options are available and what considerations go into picki开发者_JAVA百科ng a solution?

Thanks,


You cannot change the visible property of a control that has focus. Is this the problem? If so, it can be useful to keep a small control to receive focus with SetFocus : http://msdn.microsoft.com/en-us/library/aa205181(office.10).aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消