Private Sub GetControlText(ctl As Control)
If TypeOf ctl Is TextBox Then ' 判断是否Textbox, 如果Combobox 则不用删除直接下拉框中选择即可
If InStr(ctl.ControlSource, "=") = 0 Then ' 判断数据源是 直接绑定,还是间接绑定
If ctl.Locked = False And ctl.Enabled = True Then ' 判断控件是否锁定,和可用
Dim strText As String
Dim lngSelStart As Integer
Dim lngSelLong As Integer
Dim strNotRpl As String ' 截留未被选中的字符, 我们有时会把控件中 其中一部分描黑(选中),两边字符留下
lngSelStart = ctl.SelStart
lngSelLong = ctl.SelLength
strText = Nz(ctl.Text, "")
strNotRpl = Left(strText, lngSelStart) & Mid(strText, lngSelStart + lngSelLong + 1)
ctl = strNotRpl
ctl.SelLength = 0
ctl.SelStart = lngSelStart
End If
End If
End If
End Sub
Private Sub txtQuantity_KeyDown(KeyCode As Integer, Shift As Integer)
On Error Resume Next
If KeyCode = 46 Then
KeyCode = 0
'判断该子窗体的容器(子窗体/子报表控件),本人的子窗体/子报表控件名称与子窗体名称相同, 如果不同,如何引用?
If Me.Parent.Form!(Me.Name).Locked = False And Me.Parent.Form!(Me.Name).Enabled = True Then GetControlText Me.txtQuantity
End If
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) ' 不能用Form_MouseUp事件 ,只能是这个
If IsLoaded("主窗体") Then ' 这里的主窗体 是指你们自己的主窗体
Me.Parent.cboCustomer.SetFocus ' Me.Parent 就是 主窗体
Me.Parent.cboCustomer.SelStart = Len(Nz(Me.Parent.cboCustomer.Text, "")) ' cboCustomer 为主窗体上第一个可用的组合控件
End If
End Sub
作者: wx0000888 时间: 2017-8-15 09:23
原来还有更简单的办法
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DoCmd.RunCommand acCmdSelectRecord
Me.Form.Requery
End Sub 作者: wx0000888 时间: 2017-8-15 10:49 本帖最后由 wx0000888 于 2017-8-15 10:52 编辑