我在Access中创建了一个“键盘”,用于通过Android手机使用Google远程桌面以主要形式输入数据(大多数输入将使用计算机和普通键盘在本地完成)。
基于多表查询的主窗体包含数据。远程(Android)用户单击一个表单字段,然后弹出键盘,用户可以使用鼠标指针选择字母,最后单击一个OK按钮,该按钮将使用所选字母覆盖主表单的原始字段数据。
到目前为止,一切都很好,但是在离开主窗体后,出现了Write Conflict MessageBox,并且所有来自“键盘”的新编辑数据都消失了-原始数据重新出现,换句话说,什么都没有改变。
弹出键盘上的“确定”按钮的代码为:
Private Sub tOK_Click()
Dim p As String
Dim f As String
Dim c As String
Dim txtResult As String
Dim pFrmName As String
Dim frmName As String
Dim ctrl As String
'On Error GoTo errHandler
pFrmName = Me.pFrmName ' the first three or the lasr three strings can be dropped as they contain the same data
frmName = Me.frmName
ctrl = Me.ctrlName
p = pFrmName
f = frmName
c = ctrl
If p = c Then
Forms(f).SetFocus
Forms(f)(c).Value = Me.txtResult
Else
Forms(f)(p)(c).SetFocus
Forms(f)(p)(c).Value = Me.txtResult
End If
我有一个名为vkbddata的函数,该函数已放入主窗体的textBox的OnClick事件中。
如何避免输入冲突而远程输入数据?
*************************************************** ********** 2018年9月8日 功能:
Option Compare Database
Option Explicit
Function vkbdData()
'used to provide data to virtual keyboard so it can assign new data to underlying form
On Error GoTo err_handler
If Forms!f00_logon!vkbd = True Then 'if user checks virtual keyboard
Dim ctrl As Control
Dim ctrlName As String
Dim pFrmName As String ' parent form if one exists
Dim frmName As String
Dim ctrlcaption As String
Dim sValue As String
If IsNull(Screen.ActiveForm.Controls.Parent) Then
frmName = Screen.ActiveForm.ActiveControl.Name
Else
frmName = Screen.ActiveForm.Name
End If
pFrmName = Screen.ActiveForm.ActiveControl.Name
ctrlcaption = ""
ctrlName = Screen.ActiveControl.Name
If IsNull(Screen.ActiveControl.Value) Then
sValue = ""
Else
sValue = Screen.ActiveControl.Value
End If
'Debug.Print ctrlName
vkbdData = keyBoardPopUp(frmName, pFrmName, ctrlName, ctrlcaption, sValue)
End If
Exit_Form:
Exit Function
err_handler:
MsgBox Err.Description
Resume Exit_Form
End Function
Public Function keyBoardPopUp(pFrmName, frmName, ctrlName, ctrlcaption, sValue) As String
Dim frm As Object
Dim ctrl As Control
Dim sParameters As String
'strange deliminators (>,|, ...) to make it easy to tell what each parameter value is
sParameters = pFrmName & ">" & frmName & "|" & ctrlName & "^" & ctrlcaption & "~" & sValue
'Debug.Print "SParameters " & sParameters
DoCmd.OpenForm "frm_keyboard", , , , , , sParameters
End Function