Code on form load not working.

Vassago

Former Staff Turned AWF Retiree
Local time
Today, 16:42
Joined
Dec 26, 2002
Messages
4,748
I have a form that has some code behind the onload event. The code is intended to resize the access window to match that of the form. The problem is, it tries to resize the window before the actual form is loaded. I get the following error:

Runtime error 2475

You entered an expression that requires a form to be the active window.

I tried looking at the help file, only to find that the IT guys here didn't install the full help file on our new computers. (GRRRR)

Is there any way I can get this code to run? Maybe by forcing Access to wait until the form is loaded before running the code? ANYTHING! Thanks in advance!

Here is a copy of the database in Access 97 format:

Vassago
 

Attachments

Not an answer to your question, but an observation. If you have Access 2k and you can't see the help files, this points to a need to apply the service packs. I had the same problem, and SP3 sorted this out. Fixed a few other problems, too.
 
Use the Timer Event
 
Okay. This is great is most cases. However...I have a few forms that already have ontimer events that I had forgotten about. This will stop me from being able to use this code correctly. Does anyone have any other suggestions? Thanks in advance!

Vassago
 
Okay, I have an idea, but don't really know how to do it. My idea is to have this code running on an invisible form in the background in the ontimer event. Maybe setting the form it gets it's readings to whatever for the focus is set to. Is this possible?

Thanks!

Vassago :confused:
 
OnTimer event won't help with a form change and a form close. BeforeUpdate is best.
 
Thanks, but it doesn't seem to work that way. Give the error that I originally recieved. Any other suggestions? Thanks!

Vassago
 
Is there code that would set a specified form to be the active window? Then is there code that would set the active window to a specific variable? Thanks!

Vassago
 
Tried that one too. Where would I put it? I placed it almost everywhere I could think of. If it works for you, can you post it back for me? Thanks!

Vassago
 
Tried that one too. Where would I put it? I placed it almost everywhere I could think of. If it works for you, can you post it back for me? Thanks!

Vassago
 
I'm not the access guru that you all are so I'm not sure if this is something you've tried but I use this in one of my databases and it works great.

Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Err_Pause

Dim PauseTime As Variant, start As Variant

PauseTime = NumberOfSeconds
start = Timer
Do While Timer < start + PauseTime
DoEvents
Loop

Exit_Pause:
Exit Function

Err_Pause:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Pause

End Function

HTH
 

Users who are viewing this thread

Back
Top Bottom