2017-02-06 29 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

後回來,如果你有關於這個過程的更多問題。