Open Event Not Firing?

  • Thread starter shelly2 via AccessMonster.com
  • Start date
S

shelly2 via AccessMonster.com

I have the following code that runs when you click a command button. I have
further code that is supposed to run when the open event for the "Allocate"
form opens. For some reason, that code is not triggered. Any ideas?

Thank you kindly for your time.

This code is contained in a form called "Punch"

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Private Sub cmdAllocate_Click()

Me.txtTimeToday.SetFocus
IftxtTimeToday.Text = "" Then
DoCmd.GoToReord , "Punch", acPrevious, 1
Calculate
End If

DoCmd.OpenForm "Allocate Form"
DoCmd.Close acForm, "Punch"

End Sub

*~*~*~*~*~*
This is the code that's supposed to run at the open event of the "Allocate
Form":

Private Sub Form_Open()
Dim init As String
Me.txtTotalTime.SetFocus
Me.txtTotalTime.Text = Forms![Punch].txtTimeToday.Text
Me.Text4.SetFocus
Me.Text4.Text = Date
Forms![Punch].txtInitials.Text
Me.MasterInit.SetFocus
Me.MasterInit.Text = init

End Sub
 
S

Stefan Hoffmann

hi,
I have the following code that runs when you click a command button. I have
further code that is supposed to run when the open event for the "Allocate"
form opens. For some reason, that code is not triggered. Any ideas?
Have you set a breakpoint in the Form_Open event to verify if this event
is not fired?
DoCmd.OpenForm "Allocate Form"
DoCmd.Close acForm, "Punch"
The Form "Punch" will be closed immediatly after the form "Allocate
Form" is openend. There is no guaruantee that while executing the
"Allocate Form".Form_Open event the Form "Punch" still exists.

Open it with

DoCmd.OpenForm "Name", , , , , acDialog

End Sub

*~*~*~*~*~*
This is the code that's supposed to run at the open event of the "Allocate
Form":

Private Sub Form_Open()
Dim init As String
Me.txtTotalTime.SetFocus
Me.txtTotalTime.Text = Forms![Punch].txtTimeToday.Text
You don't need the .SetFocus, you can use
txtTotalTime.Value = Forms![Punch].txtTimeToday.Value


mfG
--> stefan <--
 
R

ruralguy via AccessMonster.com

I get the feeling you come from a VB background. If you reference the .Value
property (the default property of a control) there is *no* focus requirement
and it is not necessary to specify since it is the default. eg: either Forms!
Punch!txtTimeToday.Value or Forms!Punch!txtTimeToday will work. I would put
your Open code in the OnLoad event instead. The Open event is a little early
in the process to reference controls on the opening form.
I have the following code that runs when you click a command button. I have
further code that is supposed to run when the open event for the "Allocate"
form opens. For some reason, that code is not triggered. Any ideas?

Thank you kindly for your time.

This code is contained in a form called "Punch"

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Private Sub cmdAllocate_Click()

Me.txtTimeToday.SetFocus
IftxtTimeToday.Text = "" Then
DoCmd.GoToReord , "Punch", acPrevious, 1
Calculate
End If

DoCmd.OpenForm "Allocate Form"
DoCmd.Close acForm, "Punch"

End Sub

*~*~*~*~*~*
This is the code that's supposed to run at the open event of the "Allocate
Form":

Private Sub Form_Open()
Dim init As String
Me.txtTotalTime.SetFocus
Me.txtTotalTime.Text = Forms![Punch].txtTimeToday.Text
Me.Text4.SetFocus
Me.Text4.Text = Date
Forms![Punch].txtInitials.Text
Me.MasterInit.SetFocus
Me.MasterInit.Text = init

End Sub
 
N

Nick 'The database Guy'

Hi Shelly,

Try moving it to a different event.

OnLoad for usually works.

Good luck shelly
 
S

shelly2 via AccessMonster.com

Thank you both for your replies. Moving my code to the OnLoad event seems to
work. Great!

However, when I use your suggestion for .Value without setting focus, I get a
runtime 2185 error "You can't reference a property or control unless the
control has the focus."

This is how I have it written. Something wrong here?

txtTotalTime.Value = Forms![Punch].txtTimeToday.Value
Text4.Text = Date
MasterInit.Value = Forms![Punch].txtInitials.Value
 
S

shelly2 via AccessMonster.com

Hi, Stefan. Thanks for taking the time.
Have you set a breakpoint in the Form_Open event to verify if this event
is not fired?
I did, and it isn't.
DoCmd.OpenForm "Name", , , , , acDialog
No luck here, either.
Me.txtTotalTime.SetFocus
Me.txtTotalTime.Text = Forms![Punch].txtTimeToday.Text
You don't need the .SetFocus, you can use
txtTotalTime.Value = Forms![Punch].txtTimeToday.Value
This is what I just tried (see my reply below).

Grr! Seems like it should be more simple. It probably is, but I'm a
beginner, you know.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top