我试图在主表上添加一条记录,每当我点击提交时,这个表中的一个字段将根据我是否选中一个复选框,作为新行转到另一个表中。由于某种原因,记录只进入主表,而其他两个都没有。这是我的代码。
Private Sub Submit_Click()
Dim SqlString As String
Dim rs As DAO.Recordset
Dim req As Integer
SqlString = "SELECT * FROM [WorkRecord]"
SqlString1 = "SELECT * FROM [MainWork]"
sqlString2 = "SELECT * FROM [MiscelleneousWork]"
Set db = CurrentDb
Set rs = db.OpenRecordset(SqlString)
rs.MoveLast
lastnum = rs!WorkNum
rs.AddNew
rs!WorkNum = lastnum + 1
rs!WorkDate = Me.WorkDate.Value
rs!ReqNum = Me.ReqNum.Value
rs.Update
If Me.checkmain.Value = True Then
Set rs1 = db.OpenRecordset(SqlString1)
rs1.MoveLast
lastnum = rs!WorkNum
rs1.AddNew
rs1!WorkNum = lastnum + 1
rs1.Update
rs1.Close
Else
Set rs2 = db.OpenRecordset(sqlString2)
rs2.MoveLast
lastnum = rs!WorkNum
rs2.AddNew
rs2!WorkNum = lastnum + 1
rs2.Update
rs2.Close
End If
MsgBox ("Work added.")
DoCmd.Close acForm, "AddWorkRecord"
rs.Close
End Sub