回复 5楼 wufuzhang
Option Compare Database
Option Explicit
Private Sub Form_Load()
On Error GoTo ErrorHandler
Dim strSQL
As String
Dim cnn
As Object 'ADODB.Connection
Dim rst
As Object 'ADODB.Recordset
ApplyTheme Me
LoadLocalLanguage Me
If IsNull(Me.OpenArgs) Then
Me.DataEntry = True
End If
If Me.DataEntry Then
GoTo ExitHere
End If
Me.btnSave.Enabled = Me.AllowEdits
Set cnn = CurrentProject.Connection
strSQL = "SELECT * FROM [tbl5001调试号码录制] WHERE [产品编号]=" & SQLText(Me.OpenArgs)
Set rst = OpenADORecordset(strSQL, , cnn)
Me![产品编号] = rst![产品编号]
Me![产品名称] = rst![产品名称]
Me![产品状态] = rst![产品状态]
Me![判定] = rst![判定]
Me![调试人员] = rst![调试人员]
Me![存号时间] = rst![存号时间]
Me![备注] = rst![备注]
rst.Close
ExitHere:
Set rst = Nothing
Set cnn = Nothing
Exit Sub
ErrorHandler:
RDPErrorHandler Me.Name & ": Sub Form_Load()"
Resume ExitHere
End Sub
Private Sub btnSave_Click()
On Error GoTo ErrorHandler
Dim strWhere
As String
Dim strSQL
As String
Dim cnn
As Object 'ADODB.Connection
Dim rst
As Object 'ADODB.Recordset
Dim strSQL2
As String
Dim rst2
As Object 'ADODB.Recordset
Dim productName, productType As String
If Not CheckRequired(Me) Then Exit Sub
If Not CheckTextLength(Me) Then Exit Sub
Set cnn = CurrentProject.Connection
'读取[tbl4003产品名称信息]记录
strSQL2 = "SELECT * FROM [tbl4003产品名称信息]"
Set rst2 = OpenADORecordset(strSQL2, , cnn)
Do Until rst2.EOF
productName = rst2![产品名称]
productType = rst2![产品型号]
'
If Me![产品名称] = productName Then
If Len(Left(Me![产品编号], Len(productType))) = Len(productType) Then
If Left(Me![产品编号], Len(productType)) = productType Then
MsgBox "len and content is ok."
Exit Do
Else
MsgBox "content is error."
GoTo ExitHere:
End If
Else
MsgBox "len is error."
GoTo ExitHere:
End If
End If
rst2.MoveNext
Loop
strSQL = "SELECT * FROM [tbl5001调试号码录制] WHERE [产品编号]=" & SQLText(Me![产品编号])
Set rst = OpenADORecordset(strSQL, adLockOptimistic, cnn)
If rst.EOF Then
rst.AddNew
End If
rst![产品编号] = Me![产品编号]
rst![产品名称] = Me![产品名称]
rst![产品状态] = Me![产品状态]
rst![判定] = Me![判定]
rst![调试人员] = Me![调试人员]
rst![存号时间] = Me![存号时间]
rst![备注] = Me![备注]
rst.Update
rst.Close
Form_frm5001调试号码录制.RefreshDataList
MsgBoxEx LoadString("Saved Successfully."), vbInformation
If Me.DataEntry Then
ClearControlValues Me
Else
DoCmd.Close acForm, Me.Name, acSaveNo
End If
ExitHere:
Set rst = Nothing
Set cnn = Nothing
Exit Sub
ErrorHandler:
RDPErrorHandler Me.Name & ": Sub btnSave_Click()"
Resume ExitHere
End Sub
Private Sub btnCancel_Click()
On Error Resume Next
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
代码就是这个,麻烦帮我看看,要怎么修改,谢谢