2017-02-06 97 views
0

任何人都可以帮我 我有MS Access 2013 和Sharepoint在线(办公室365),我需要从主数据库SQL到在线SP的数据,我使用Access来做到这一点,但它是手动的,我需要它自动过夜任何人有一个想法,我们如何能做到这一点。 我使用MS VB 这些代码:微软访问每晚视觉基本自动

Option Compare Database 

Private Sub DeleteAdd_Click() 

    On Error Resume Next 

    DoCmd.SetWarnings False 
    DoCmd.OpenQuery "DeleteTest", acViewNormal, acEdit 
    DoCmd.SetWarnings True 
    DoCmd.SetWarnings False 
    DoCmd.OpenQuery "AddTest", acViewNormal, acEdit 
    DoCmd.SetWarnings True 

End Sub 

Private Sub lisACTORS_Click() 

    MsgBox lisACTORS.Value 
End Sub 

反正我能做到这一点在VB或任务时间表

+0

您可以尝试使用例如每小时滴答一次的计时器,并检查小时是否等于午夜,然后执行您的代码。 – obl

+0

我该怎么做? – Ace

回答

1

我已经在Windows这样做过窗体应用程序,我不知道是什么您正在运行的应用程序的类型。您添加一个定时器控件,启用定时器并将定时器间隔设置为60 * 1000 = 60000(相当于一个小时)。然后在Timer.Tick事件(https://msdn.microsoft.com/en-us/library/system.windows.forms.timer.tick(v=vs.110).aspx),写:

If Now.Hour.ToString = "23" Then 'Checks if the current hour is midnight 
    'Execute code 
End If 
+0

Thanks Obl,我有删除查询后,我有添加查询,我需要在一夜之间运行这2个查询 – Ace

+0

所以,我把'执行代码'是你把你的代码删除查询和添加查询。那样,这两件事情会在凌晨12:00到凌晨1:00之间发生。您还必须让程序继续运行才能正常工作。如果我回答您的问题,我将非常感谢您将其标记为答案,谢谢。 – obl

+0

谢谢Obl,我尝试了,我还没有成功,仍然没有和我一起工作 – Ace

0

我曾经在以前的工作我有一个几年前这样做。按着这些次序 。 。 。

Create an AutoExec macro 

If you have already created a macro that contains the actions that you want to occur when the database starts, just rename the macro AutoExec, and it will run the next time that you open the database. Otherwise, follow these steps to create a macro: 

    On the Create tab, in the Other group, click Macro. If this command is unavailable, click the arrow beneath either the Module or the Class Module button, and then click Macro. 

    In the Macro Builder, in the first empty Action cell, select the action that you want to perform. If applicable, under Action Arguments, type the appropriate values in the argument boxes. 

    If you cannot find the action you want, on the Design tab, in the Show/Hide group, make sure Show All Actions is selected. This expands the list of actions that you can use, but the list will include some actions that will only run if the database is granted trusted status. For more information, see the articles Decide whether to trust a database or How database objects behave when trusted and untrusted. 

    Repeat step 2 for each additional action you want to occur. 

    Click Save, and in the Save As dialog box, type AutoExec. 

    Click OK and then close the Macro Builder. The new macro will run the next time that you open the database. 

要触发整个事情,您需要使用Windows任务计划程序。所有细节请参阅下面的链接。

https://www.sevenforums.com/tutorials/11949-elevated-program-shortcut-without-uac-prompt-create.html

后回来,如果你有关于这个过程的更多问题。