Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

database - How to run my VBA code between specific hours for each week in MS Access application

I had a MS Access application that is used in multiuser environment. I want to make maintanence every thursday between 15:00 and 16:00. At this point I have two issues to consider.

Firstly, The users who may be entering to application before 15:00.
Secondly, the users who will be entering between 15:00-16:00

For the second scenario, I need to prevent my users to access the MS Access application. For this purpose, I have written the following code into the load event of my beginning form.

Private Sub Form_Load()
MsgBox "Between 15.00 and 16.00 on Thursdays access is not available due to maintenance", vbOKOnly*  
DoCmd.CloseDatabase
End Sub

It worked in a way I would like. The only thing is now to restrict it to work between specific hours as I described. How can I integrate time parameter to my code?

And for first scenario, For all users in the system wherever they are, close database function should be working and Application should be closed automatically.

question from:https://stackoverflow.com/questions/65868881/how-to-run-my-vba-code-between-specific-hours-for-each-week-in-ms-access-applica

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To check for time period:

Dim T As Date
T = Time()
If Weekday(Date()) = 5 And T >= #3:00:00 PM# And T <= #4:00:00 PM# Then

Forcing a db to close risks corrupting data but I suppose it can be done. This is a common topic and should be able to find many examples.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...