fuction to click a command button (2 Viewers)

ROMADOZ

Registered User.
Local time
Today, 16:09
Joined
May 14, 2008
Messages
31
I am trying to set up my database to check the local time and then, if the time is after 16:30 run an update. my update is a form that runs from the on click of a command button on another form. My question... after searching the forum and finding nothing, is... how do I make access click the button for me? My code looks like this so far. I have the time set for 09:30 right now for testing purposes.

Option Compare Database
Public Function TaskUpdater()
If Time() > "9:30:00" Then
DoCmd.OpenForm "frm_training", acNormal, "", "", acEdit, ""

End If
End Function


Help?:confused:
 
Local time
Today, 16:09
Joined
Mar 4, 2008
Messages
3,856
You can put your code in the form's timer event and set it to run every so often.

Some people create an invisible form that run administrative stuff like this on a timer in the background so users never see it.
 

ROMADOZ

Registered User.
Local time
Today, 16:09
Joined
May 14, 2008
Messages
31
I already have a hidden form in the background that keeps users from closing via the close button because I have an on click set up for an exit button to copy the DB to a seperate location. With all that said, I want this event to happen on close(before my DB copy) if the time is after 1630 (our closing time). It is a fairly large DB and an update can be very time consuming. Also, the DB is not constantly open.
 

wazz

Super Moderator
Local time
Tomorrow, 05:09
Joined
Jun 29, 2004
Messages
1,711
an invisible form is what most people do but to call an event on another form i think you can use
Form_frmName cmdButton_click()
... i think.
 

ROMADOZ

Registered User.
Local time
Today, 16:09
Joined
May 14, 2008
Messages
31
So, I heard from a local friend something about set focus on the command button and then sendkeys mouse click... can that work?
 

wazz

Super Moderator
Local time
Tomorrow, 05:09
Joined
Jun 29, 2004
Messages
1,711
my first post wasn't quite right. the correct way is:
Form_frmName.cmdButton_click
but, the procedure you are calling must be public!

the setfocus and sendkeys could possibly work but i haven't tried. sounds like macros.
 

DCrake

Remembered
Local time
Today, 22:09
Joined
Jun 8, 2005
Messages
8,626
Simple Software Solutions

It looks like you never work late...

to mimic the clicking of a comand button simple use the following syntax

CmdButton_Click

Where CmdButton is the name of the command button you want to simulate. Other than that copy the on click code from the command button to a sub routine and call the sub routine instead of trying to click the button.

Call OnClickRoutine

CodeMaster::cool:
 

ROMADOZ

Registered User.
Local time
Today, 16:09
Joined
May 14, 2008
Messages
31
I did that and got a complile error, member not found. Then I remembered what you said that it had to be a public sub... so I went and changed it from private to pubilc. Now, I get a type mismatch error. Ideas?
 

ROMADOZ

Registered User.
Local time
Today, 16:09
Joined
May 14, 2008
Messages
31
My code looks like this now

Option Compare Database
Public Function TaskUpdater()
If Time() > "9:30:00" Then
DoCmd.OpenForm "frm_training", acNormal, "", "", acEdit, ""
Form_frm_Training.btnAddUpdatedTasks_Click
End If
End Function
 

wazz

Super Moderator
Local time
Tomorrow, 05:09
Joined
Jun 29, 2004
Messages
1,711
change
DoCmd.OpenForm "frm_training", acNormal, "", "", acEdit, ""
to
DoCmd.OpenForm "frm_training", acNormal, "", "", acEdit 'no open args

also change your time to #9:30:00# (AM will be added automatically (or PM if you change the time)).
also add Option Explicit below Option Compare Database.
 
Last edited:

Users who are viewing this thread

Top Bottom