Private Sub Form_DblClick(Cancel As Integer)
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Set cn = CurrentProject.Connection
sql = "select * from tblGSdengji"
rs.Open sql, cn, adOpenKeyset, adLockPessimistic, 1
' rs.AddNew
With Forms!frmGSdengji1.Form
!cboxiaozu = rs("小组")
!txtpinghao = rs("品号")
!txtgj = rs("工件")
!cbogx = rs("工序")
!cbogr = rs("操作工")
!txtNo.SetFocus
rs.Update
rs.Close
cn.Close
Set cn = Nothing
End With
End Sub
我知道问题出在sql = "select * from tblGSdengji" 代码,但对于选中的记录,我不知代码上该如何表达,所以特向大家请教,在此先谢了。
你是不是这么个意思:
Private Sub Form_DblClick(Cancel As Integer)
Dim rs As New ADODB.Recordset
Dim sql As String
Dim ctls as controls
set ctls=Forms("frmGSdengji1").controls
sql = "select * from tblGSdengji"
rs.Open sql, CurrentProject.Connection, adOpenKeyset, adLockPessimistic
rs.moveLast
ctls("cboxiaozu").value = rs("小组").value
ctls("txtpinghao").value = rs("品号").value
ctls("txtgj").value= rs("工件").value
ctls("cbogx").value = rs("工序").value
ctls("cbogr").value = rs("操作工").value
rs.close
set rs=nothing