What does this weird runtime behavior mean?

G

Guest

Here is the open event:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ER
'Reset the mode
Mode_AI = "v"
'Set the focus to the first field
Me![Received Date].SetFocus
'Reset the buttons on the form
Forms![Assignment Information].[Cancel Button].Enabled = True
Forms![Assignment Information].[Save Button].Enabled = False
Exit Sub
ER:
MsgBox Err.Description, , "Form_Open"
End Sub

I put msgbox statements after every statement.
After the 'Mode_AI = "v"' line runs the Activate event fires
Does this mean the DB is corrupted?
 
D

Douglas J. Steele

That code shouldn't be in the Open event: it's too early. Put it in the Load
event instead.

The Open event is really intended for code that checks whether or not the
form should actually be opened. If it shouldn't, you set Cancel = True, and
the form shuts down.
 
G

Guest

Thanks for the response.
The code I posted is existing code that has run ok for at least 6 months
(even thouh it may not be the best - I did not write it).
Database started getting errors yesterday and I ran the LDB viwer which
confirmed two current users were logged off. So I suspect a database
corruption.

My specific question was why would the activate event fire before all
statements in the open event had run?


Douglas J. Steele said:
That code shouldn't be in the Open event: it's too early. Put it in the Load
event instead.

The Open event is really intended for code that checks whether or not the
form should actually be opened. If it shouldn't, you set Cancel = True, and
the form shuts down.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


mscertified said:
Here is the open event:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ER
'Reset the mode
Mode_AI = "v"
'Set the focus to the first field
Me![Received Date].SetFocus
'Reset the buttons on the form
Forms![Assignment Information].[Cancel Button].Enabled = True
Forms![Assignment Information].[Save Button].Enabled = False
Exit Sub
ER:
MsgBox Err.Description, , "Form_Open"
End Sub

I put msgbox statements after every statement.
After the 'Mode_AI = "v"' line runs the Activate event fires
Does this mean the DB is corrupted?
 
D

Douglas J. Steele

Because you're trying to refer to controls that may or may be completed
instantiated, it doesn't surprise me that weird things are happening. I
wouldn't necessarily assume that means corruption.

If you're concerned about corruption, import everything into a new database.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


mscertified said:
Thanks for the response.
The code I posted is existing code that has run ok for at least 6 months
(even thouh it may not be the best - I did not write it).
Database started getting errors yesterday and I ran the LDB viwer which
confirmed two current users were logged off. So I suspect a database
corruption.

My specific question was why would the activate event fire before all
statements in the open event had run?


Douglas J. Steele said:
That code shouldn't be in the Open event: it's too early. Put it in the
Load
event instead.

The Open event is really intended for code that checks whether or not the
form should actually be opened. If it shouldn't, you set Cancel = True,
and
the form shuts down.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


mscertified said:
Here is the open event:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ER
'Reset the mode
Mode_AI = "v"
'Set the focus to the first field
Me![Received Date].SetFocus
'Reset the buttons on the form
Forms![Assignment Information].[Cancel Button].Enabled = True
Forms![Assignment Information].[Save Button].Enabled = False
Exit Sub
ER:
MsgBox Err.Description, , "Form_Open"
End Sub

I put msgbox statements after every statement.
After the 'Mode_AI = "v"' line runs the Activate event fires
Does this mean the DB is corrupted?
 
G

Guest

I moved all the code from my Form_Open event to the Form_Load event. However,
I'm still getting an error in the Form_Current event. Referencing
Screen.Active control gives a 2474 error (control not in active window).
Screen.Activeform also fails with error 2475 (form is not the active window).
This app is really weird it uses a pseudo tab-control (written under Access
2.0 before tab control existed) and it uses the TAG property of command
buttons to set up the subforms (for each tab) when the tab buttons are
pressed.

Douglas J. Steele said:
Because you're trying to refer to controls that may or may be completed
instantiated, it doesn't surprise me that weird things are happening. I
wouldn't necessarily assume that means corruption.

If you're concerned about corruption, import everything into a new database.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


mscertified said:
Thanks for the response.
The code I posted is existing code that has run ok for at least 6 months
(even thouh it may not be the best - I did not write it).
Database started getting errors yesterday and I ran the LDB viwer which
confirmed two current users were logged off. So I suspect a database
corruption.

My specific question was why would the activate event fire before all
statements in the open event had run?


Douglas J. Steele said:
That code shouldn't be in the Open event: it's too early. Put it in the
Load
event instead.

The Open event is really intended for code that checks whether or not the
form should actually be opened. If it shouldn't, you set Cancel = True,
and
the form shuts down.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Here is the open event:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ER
'Reset the mode
Mode_AI = "v"
'Set the focus to the first field
Me![Received Date].SetFocus
'Reset the buttons on the form
Forms![Assignment Information].[Cancel Button].Enabled = True
Forms![Assignment Information].[Save Button].Enabled = False
Exit Sub
ER:
MsgBox Err.Description, , "Form_Open"
End Sub

I put msgbox statements after every statement.
After the 'Mode_AI = "v"' line runs the Activate event fires
Does this mean the DB is corrupted?
 

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