Ms access 每30秒运行一次VBA功能(从启动开始)(访问)
因此,我有我的代码,应该在启动access DB时执行 (它从文件夹导入文件) 我的想法是在启动时运行宏,然后打开函数并使用Ms access 每30秒运行一次VBA功能(从启动开始)(访问),ms-access,vba,Ms Access,Vba,因此,我有我的代码,应该在启动access DB时执行 (它从文件夹导入文件) 我的想法是在启动时运行宏,然后打开函数并使用 Application.OnTime Now + TimeValue("00:00:30"), "import_files" corse的不起作用,因为它与access不兼容。。。所以你可以这样使用它: Excel.Application.OnTime Now + TimeValue("00:00:30"), "import_files" 只是从那以后你什么都跑不了
Application.OnTime Now + TimeValue("00:00:30"), "import_files"
corse的不起作用,因为它与access不兼容。。。所以你可以这样使用它:
Excel.Application.OnTime Now + TimeValue("00:00:30"), "import_files"
只是从那以后你什么都跑不了
有什么简单的解决办法吗
像这样基本的东西
Function Import_files
do every 30 seconds
run code
loop
end function
谢谢你的帮助!
(在VBA中不是很好): 可以考虑使用<强>窗体的时间间隔属性< /强>。您可以打开一个表单(隐藏),让计时器触发代码 示例
下面的示例演示如何通过在按钮上显示和隐藏图标在窗体上创建闪烁按钮。表单的加载事件过程将表单的TimerInterval属性设置为1000,以便每秒切换一次图标显示
Sub Form_Load()
Me.TimerInterval = 1000
End Sub
Sub Form_Timer()
Static intShowPicture As Integer
If intShowPicture Then
' Show icon.
Me!btnPicture.Picture = "C:\Icons\Flash.ico"
Else
' Don't show icon.
Me!btnPicture.Picture = ""
End If
intShowPicture = Not intShowPicture
End Sub
要使用此示例代码:注意:根据您使用的版本,您的屏幕看起来会有所不同。
您可以在谷歌上搜索:access me.timerinterval示例。
A.取消选择按钮并选择表单属性。
B.单击属性页中窗体的事件加载器。
C.双击代码生成器。
D.选择全部,然后从此处粘贴代码。
供参考:
对于代码mmehta所做的;你可以把它放在一个模块里
他向你展示了如何扩展你的思维过程。
你建议:
Function Import_files
do every 30 seconds
run code
if needed reset any variables
他阐述说:
Function Import_files
Do
Pause(30)
run code (You're code here or better yet put your code in a sub routine and call the routine.)
Loop
End Function
Option Compare Database
Option Explicit
Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Error_GoTo
Dim PauseTime As Variant
Dim Start As Variant
Dim Elapsed As Variant
PauseTime = NumberOfSeconds
Start = Timer
Elapsed = 0
Do While Timer < Start + PauseTime
Elapsed = Elapsed + 1
If Timer = 0 Then
' Crossing midnight
PauseTime = PauseTime - Elapsed
Start = 0
Elapsed = 0
End If
DoEvents
Loop
Exit_GoTo:
On Error GoTo 0
Exit Function
Error_GoTo:
Debug.Print Err.Number, Err.Description, Erl
GoTo Exit_GoTo
End Function
Sub msgUser()
Dim x As Integer
x = MsgBox("Click 'OK' to continue.", vbOKOnly, "Ready?")
End Sub
选项比较数据库
选项显式
公共功能暂停(秒数作为变量)
关于错误转到错误\u转到
Dim PauseTime作为变体
变暗启动作为变型
变型
暂停时间=秒数
开始=计时器
已用时间=0
定时器<启动+暂停时间时执行
已用=已用+1
如果计时器=0,则
“过了午夜
PauseTime=PauseTime-已过
开始=0
已用时间=0
如果结束
多芬特
环
退出后藤:
错误转到0
退出功能
错误_GoTo:
调试.打印错误号,错误描述,错误
转到出口
端函数
亚msgUser()
作为整数的Dim x
x=MsgBox(“单击“确定”继续。”,vbOKOnly,“准备好了吗?”)
端接头
可以考虑使用<强>窗体的时间间隔属性< /强>。您可以打开一个表单(隐藏),让计时器触发代码
示例下面的示例演示如何通过在按钮上显示和隐藏图标在窗体上创建闪烁按钮。表单的加载事件过程将表单的TimerInterval属性设置为1000,以便每秒切换一次图标显示
Sub Form_Load()
Me.TimerInterval = 1000
End Sub
Sub Form_Timer()
Static intShowPicture As Integer
If intShowPicture Then
' Show icon.
Me!btnPicture.Picture = "C:\Icons\Flash.ico"
Else
' Don't show icon.
Me!btnPicture.Picture = ""
End If
intShowPicture = Not intShowPicture
End Sub
要使用此示例代码:注意:根据您使用的版本,您的屏幕看起来会有所不同。
您可以在谷歌上搜索:access me.timerinterval示例。
A.取消选择按钮并选择表单属性。
B.单击属性页中窗体的事件加载器。
C.双击代码生成器。
D.选择全部,然后从此处粘贴代码。
供参考:
对于代码mmehta所做的;你可以把它放在一个模块里
他向你展示了如何扩展你的思维过程。
你建议:
Function Import_files
do every 30 seconds
run code
if needed reset any variables
他阐述说:
Function Import_files
Do
Pause(30)
run code (You're code here or better yet put your code in a sub routine and call the routine.)
Loop
End Function
Option Compare Database
Option Explicit
Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Error_GoTo
Dim PauseTime As Variant
Dim Start As Variant
Dim Elapsed As Variant
PauseTime = NumberOfSeconds
Start = Timer
Elapsed = 0
Do While Timer < Start + PauseTime
Elapsed = Elapsed + 1
If Timer = 0 Then
' Crossing midnight
PauseTime = PauseTime - Elapsed
Start = 0
Elapsed = 0
End If
DoEvents
Loop
Exit_GoTo:
On Error GoTo 0
Exit Function
Error_GoTo:
Debug.Print Err.Number, Err.Description, Erl
GoTo Exit_GoTo
End Function
Sub msgUser()
Dim x As Integer
x = MsgBox("Click 'OK' to continue.", vbOKOnly, "Ready?")
End Sub
选项比较数据库
选项显式
公共功能暂停(秒数作为变量)
关于错误转到错误\u转到
Dim PauseTime作为变体
变暗启动作为变型
变型
暂停时间=秒数
开始=计时器
已用时间=0
定时器<启动+暂停时间时执行
已用=已用+1
如果计时器=0,则
“过了午夜
PauseTime=PauseTime-已过
开始=0
已用时间=0
如果结束
多芬特
环
退出后藤:
错误转到0
退出功能
错误_GoTo:
调试.打印错误号,错误描述,错误
转到出口
端函数
亚msgUser()
作为整数的Dim x
x=MsgBox(“单击“确定”继续。”,vbOKOnly,“准备好了吗?”)
端接头
尝试以下计时器功能
Function Import_files
Do
Pause(30)
run code
Loop
end function
Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Error_GoTo
Dim PauseTime As Variant
Dim Start As Variant
Dim Elapsed As Variant
PauseTime = NumberOfSeconds
Start = Timer
Elapsed = 0
Do While Timer < Start + PauseTime
Elapsed = Elapsed + 1
If Timer = 0 Then
' Crossing midnight
PauseTime = PauseTime - Elapsed
Start = 0
Elapsed = 0
End If
DoEvents
Loop
Exit_GoTo:
On Error GoTo 0
Exit Function
Error_GoTo:
Debug.Print Err.Number, Err.Description, Erl
GoTo Exit_GoTo
End Function
函数导入\u文件
做
暂停(30)
运行代码
环
端函数
公共功能暂停(秒数作为变量)
关于错误转到错误\u转到
Dim PauseTime作为变体
变暗启动作为变型
变型
暂停时间=秒数
开始=计时器
已用时间=0
定时器<启动+暂停时间时执行
已用=已用+1
如果计时器=0,则
“过了午夜
PauseTime=PauseTime-已过
开始=0
已用时间=0
如果结束
多芬特
环
退出后藤:
错误转到0
退出功能
错误_GoTo:
调试.打印错误号,错误描述,错误
转到出口
端函数
尝试以下计时器功能
Function Import_files
Do
Pause(30)
run code
Loop
end function
Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Error_GoTo
Dim PauseTime As Variant
Dim Start As Variant
Dim Elapsed As Variant
PauseTime = NumberOfSeconds
Start = Timer
Elapsed = 0
Do While Timer < Start + PauseTime
Elapsed = Elapsed + 1
If Timer = 0 Then
' Crossing midnight
PauseTime = PauseTime - Elapsed
Start = 0
Elapsed = 0
End If
DoEvents
Loop
Exit_GoTo:
On Error GoTo 0
Exit Function
Error_GoTo:
Debug.Print Err.Number, Err.Description, Erl
GoTo Exit_GoTo
End Function
函数导入\u文件
做
暂停(30)
运行代码
环
端函数
公共功能暂停(秒数作为变量)
关于错误转到错误\u转到
Dim PauseTime作为变体
变暗启动作为变型