好的,所以我正在尝试编写 VBA 代码以尽可能地自动化。我需要它做的是从表中的字段中读取,如果它满足条件,则将其复制到新表中。这是为了旋转的目的。如果CurrentDate
等于NextDateOut
该项目的任何值,我想转到某个表,但也想更新当前表中的值。 NextDateOut
将是LastDateOut
表中的新值,NextDateIn
距 NextDateIn 10 天,从那时起NextDateOut
10 天。我可以编写此数学逻辑,它只是将我的表中的值与我现在的常量进行比较,CurrentDate
并在条件满足时更新值并将值写入某个表。
这是到目前为止的代码,并且试图弄清楚它也有很多错误。
Option Explicit
Sub Run()
'Declarations for grabbing data from the database for the VBA
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
'Open connection to current Access database
Set db = CurrentDb()
'Declarations for variables to deal with dates
Dim CurrentDate As Date
Dim NextDateOut As Date
Dim NextDateIn As Date
Dim LastDateOut As Date
Dim LastDateIn As Date
'Setting a consistant value, technically not a constant value since there's no "const"
CurrentDate = Date
'Will take this out eventually
MsgBox (CurrentDate)
strSQL = "SELECT Next Date Out FROM Tapes Where Next Date Out = CurrentDate"
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
With rst
If .RecorCount > 0 Then
.MoveFirst
.Edit
!Next Date Out = (CurrentDate+20)
.Update
End If
End With
End Sub
提前致谢!!!我正在取得进展,但在路上碰壁了。再次感谢!!!