0

我有在 SharePoint 中持续输入的数据;此表在 MS Access 中链接,并且每月一次,我通过将数据从实时 SharePoint 数据库复制到静态 Access 数据库来冻结数据。我使用 SQL 查询来执行此操作,并且效果很好。

这是查询的要点(我对其进行了简化并删除了此示例的字段):

INSERT INTO [CALL DATA] ( FiscalMonth, FiscalYear, EncDateTime, TimeDuration )
SELECT "07-Apr" AS FiscalMonth, "FY13" AS FiscalYear, 
CallAttempts.[Attempt Date & Time], CallAttempts.[Attempt Duration (Mins)]
FROM CallAttempts
WHERE ((CallAttempts.[Attempt Date & Time]>#4/1/2013#) AND 
       (CallAttempts.[Attempt Date & Time]<#5/1/2013#) AND 
       (CallAttempts.[Attempt Duration (Mins)] IS NOT NULL));

如您所见,每个月,我都必须手动更新此查询的部分内容:日期和时间约束的值FiscalMonth和值。FiscalYear这对我来说很好(我编写了代码),但我必须把它交给非技术人员。

我不是很精通 Access -我可以创建一个用户表单来在它执行之前更新这个查询(我正在考虑添加下拉选择和一个数据选择器来执行)? 这甚至可能吗?

还是有更好的方法来解决这个问题?

4

1 回答 1

1

是的,你可以很容易地。这应该让你开始:

Private Sub cmdGo_Click()
   Dim Mo As Integer
   Dim Yr As Integer
   Dim strSQL As String
   Dim Mon As String
   Dim DateStart As Date
   Dim DateEnd As Date

   strSQL = ""
   strSQL = strSQL & "INSERT INTO [call data] " & vbCrLf
   strSQL = strSQL & "            (fiscalmonth, " & vbCrLf
   strSQL = strSQL & "             fiscalyear, " & vbCrLf
   strSQL = strSQL & "             encdatetime, " & vbCrLf
   strSQL = strSQL & "             timeduration) " & vbCrLf
   strSQL = strSQL & "SELECT '07-@Mon' AS FiscalMonth, " & vbCrLf
   strSQL = strSQL & "       'fy@yr'   AS FiscalYear, " & vbCrLf
   strSQL = strSQL & "       callattempts.[attempt date & time], " & vbCrLf
   strSQL = strSQL & "       callattempts.[attempt duration (mins)] " & vbCrLf
   strSQL = strSQL & "FROM   callattempts " & vbCrLf
   strSQL = strSQL & "WHERE  ( ( callattempts.[attempt date & time] >= #@DateStart# ) " & vbCrLf
   strSQL = strSQL & "         AND ( callattempts.[attempt date & time] <#@DateEnd# ) " & vbCrLf
   strSQL = strSQL & "         AND ( callattempts.[attempt duration (mins)] IS NOT NULL ) )"

   Mo = Me.cboMonth.Value
   Yr = Me.cboYear.Value
   Mon = MonthName(Mo, True)
   DateStart = DateSerial(Yr, Mo, 1)
   DateEnd = DateAdd("m", 1, DateStart)
   strSQL = Replace(strSQL, "@mon", Mon)
   strSQL = Replace(strSQL, "@Yr", Yr)
   strSQL = Replace(strSQL, "@DateStart", DateStart)
   strSQL = Replace(strSQL, "@DateEnd", DateEnd)

   'Debug.Print strSQL
End Sub
于 2013-05-10T16:58:36.363 回答