Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screen.ActiveForm

Status
Not open for further replies.

Chopstik

Technical User
Oct 24, 2001
2,180
US
I have a user who is receiving an error message when trying to go from one form to another. Since this is an Access application that I neither created nor am terribly familiar with, I asked her what the error message was and where it was occurring (in the code). Since she is off-site in another location, and since she is apparently not very computer literate, the best I could get was the error message:

Run-time error '440'
Method 'ActiveForm' of object 'Screen' failed


From what I remember, this seems like an issue with the user not having correct .dll files or something similar. She then explained that she had received an OS upgrade from 95 to NT (4.0 or 2000?) a few weeks ago and had been having issues on other things in the same db. So now, I am thinking that this may be a MDAC problem, but have forgotten how to best figure out what version it is and how to get the user the corrected version. Does anyone have any ideas on this or, if this is not the correct solution, a better idea as to how to resolve? Thanks!

Everything is absolute. Everything else is relative.
 
Does the database utilize ADO or DAO references?


"I know what you're t'inkin', ma petite. Dat Gambit... still de suave one, no?"
 
Via Tools, References (when in Module Design mode), it is utilizing the Microsoft DAO 3.51 Object Library. I checked the version against that of another user that I know is working, and the version is the same (if that makes any difference). Thinking........thinking........thinking....... that I need a cup of tea.....

Nice X-Men tag line, there. :)

Everything is absolute. Everything else is relative.
 
Ah...but if she upgraded, I bet that her refernces do not have the DAO 3.6 reference checked...

I would look into that.


"I know what you're t'inkin', ma petite. Dat Gambit... still de suave one, no?"
 
Hi!

Look in the code and find out where the Screen object is being used. Post the code and we may get a better idea. Look for code that would run when forms are being opened or closed. In particular, look for code that call a public function then procedes to close the form. I know that one difference from 95 to NT is that NT is better at parallel processing and this error sounds like there was no active form when the code ran.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Gambit,

I know that she does not have references to ver 3.6, but neither do any other users and there have been no other complaints on this issue.

Jeff,

Here is the code (somewhat lengthy, apologise for that). I see where the Screen.ActiveForm is referenced twice and what you suggest may be a possible culprit (if I am interpreting your advice correctly), but perhaps someone more acquainted with this would offer a better suggestion. As an aside, I spoke with the boss who originally helped with this development and he said this has apparently been a problem before and his solution has been to reference this object directly as opposed to setting a variable for it in the code. Perhaps that jibes with your suggestion? Thanks.

Dim curForm As Form
Dim updatingform As Form
Dim currset As Recordset
Dim OriginalFormName As String
Dim conts As Containers
Dim cont As Container
Dim docs As Documents
Dim doc As Document
Dim OriginalFormClosed As Boolean
OriginalFormClosed = False
DoCmd.Echo False
DoCmd.SetWarnings False

'Get the identity of the current screen
Set originalform = Screen.ActiveForm
OriginalFormName = originalform.Name


'If originalform.Dirty = True Then

If RecordInvalid(OriginalFormName) Then
GoTo OpenFormWithCloseExit
End If

MultiRecordVal = CheckMultiRecord(OriginalFormName)
If Len(MultiRecordVal) > 0 Then
MsgBox "Please enter a value in " & MultiRecordVal & " before continuing. Thank you."
GoTo OpenFormWithCloseExit
End If
'originalform.Refresh
'End If

'Change the SQL of the form we're opening to filter the records.
If FilterQuestion = "Filter" Then
Call FilterViewSQL(AnyFormName, Forms![Main]![Lease_ID])
End If

'Open the form we want to get to and maximize it
DoCmd.OpenForm AnyFormName
DoCmd.Maximize

'We need to keep the Main form open to have access to its data, so
'if the current form is the Main form, don't close it, just hide it
If OriginalFormName = "Main" Then
frommain = True
originalform.Visible = True
Else
DoCmd.Close acForm, OriginalFormName
End If

OriginalFormClosed = True

'Set the Last Modified date on the form we just left if it was changed
If Len(updatecheck) > 0 Then
'The Risk Managment form uses the Last Modified Main field in the location info table.
'All other forms use the Last Modified field in their respective tables.
'The main form no longer needs such a field because it is now read only but is included
'for safety's sake
If OriginalFormName = "Risk_Mgmt" Or OriginalFormName = "Main" Then
DoCmd.RunSQL "UPDATE " & updatecheck & " SET " & "[Last_Modified_Main]" & " = Date() WHERE [Lease_ID] = Forms![Main]![Lease_ID]"
DoCmd.RunSQL "UPDATE " & updatecheck & " SET " & "[Last_Modified_Name_Main]" & " = '" & SQLUserName & "' WHERE [Lease_ID] = Forms![Main]![Lease_ID]"
Else
DoCmd.RunSQL "UPDATE " & updatecheck & " SET " & "[Last_Modified]" & " = Date() WHERE [Lease_ID] = Forms![Main]![Lease_ID]"
DoCmd.RunSQL "UPDATE " & updatecheck & " SET " & "[Last_Modified_Name]" & " = '" & SQLUserName & "' WHERE [Lease_ID] = Forms![Main]![Lease_ID]"
End If
updatecheck = ""
End If

'If the form we're going to open requires a filter to match the lease id
'of the main screen, apply that filter
If FilterQuestion = "Filter" Then
'''Change
'DoCmd.ApplyFilter , "[Lease_ID] = [Forms]![Main]![Lease_ID]"
Set curForm = Screen.ActiveForm

'If there's no record present currently, create one
If Not GetFormGroup(AnyFormName) Then
'Except skip for the new Rent/Expense form -- David Hirsch 2/8/00
If Not curForm.Name = "Rent/Expense Escalations" Then
If IsNull(curForm![Lease_ID]) Then
Set currset = curForm.RecordsetClone
currset.AddNew
currset("Lease_ID") = [Forms]![Main]![Lease_ID]
currset.Update
DoCmd.Requery

'If we're creating the first Address record, it needs to be
'the property address
If curForm.Name = "Addresses" Then
curForm![Lease Type] = "Property"
curForm![Country] = ReadPrefs("Country")
End If
'If we're creating the first Option record, it needs to have
'No Renewal set if this is a lease record
If curForm.Name = "Options" Then
If Forms!Main![Lease Type] = "Lease" Then
curForm![Option Type] = "No Renewal"
End If
End If
End If
End If
End If

'Finally, we want to always start with the Property record on the Address
'screen, so cycle through the records until we find it.
If curForm.Name = "Addresses" Then
Set currset = curForm.RecordsetClone
currset.MoveFirst
Do While Not curForm![Address Type] = "Property"
currset.MoveNext
'currecordnum = currecordnum + 1
curForm.Bookmark = currset.Bookmark
Loop
curForm.Refresh
End If

Dim AnyForm As Form
Set AnyForm = Forms(AnyFormName)

'Check whether the form we're opening should be modifiable and adjust it accordingly
If modifycheck = Forms![Main]![Lease_ID] Then
LockVar = False
Forms(AnyFormName)![Header].BackColor = 8454143
Forms(AnyFormName)![Header Text].BackColor = 8454143
Else
LockVar = True
Forms(AnyFormName)![Header].BackColor = 255
Forms(AnyFormName)![Header Text].BackColor = 255
End If

'Check if the user has the priveleges to modify this form
If GetFormGroup(AnyFormName) Or (AnyFormName = "Actual Expenses" And Not CurrentUserInGroup("CrestarAdmin")) Then
LockVar = True
Forms(AnyFormName)![Header].BackColor = 255
Forms(AnyFormName)![Header Text].BackColor = 255
Else
CanModifyForm = "Modify"
End If

temp = LockForm(AnyForm, LockVar)

End If

OpenFormWithCloseExit:

DoCmd.Echo True
Exit Function

OpenFormWithCloseErrors:

curError = Format(Err)
On Error Resume Next

If OriginalFormClosed Then
If OriginalFormName = "Main" Then
Forms![Main].Visible = True
Else
DoCmd.OpenForm OriginalFormName
DoCmd.Maximize
End If
End If

If curError = 2603 Then
MsgBox "You don't have permission to open the " & AnyFormName & " screen."
Else
MsgBox "Couldn't open the " & AnyFormName & " screen. Error # " & curError
End If

GoTo OpenFormWithCloseExit

Exit Function
End Function


Everything is absolute. Everything else is relative.
 
Hi!

Two more things. Where does this code reside? and, if it is in a public function, where is the function called from?



Jeff Bridgham
bridgham@purdue.edu
 
It is in a module called "Functions", and I'm assuming that it is public since there is no declaration. It reads:

Function OpenFormWithClose(AnyFormName As String, FilterQuestion As String)

It is called with the OnClick event of a button that resides on one page that is supposed to call another page.

Everything is absolute. Everything else is relative.
 
Hi!

The only other thing I notice is that the variable originalform isn't declared. I don't see why that would get you the specific error you are getting but it wouldn't be the first time I didn't understand why Access chooses a particular error message.

If declaring the variable doesn't help then maybe you can email me the database (zipped) and I could try to follow all of the function calls you have in the code.

hth


Jeff Bridgham
bridgham@purdue.edu
 
You and me both (as far as not understanding why Access gives some of the error messages it does). For the moment, I think I'll pass this back to the manager and let him try his solution. When/if I have more time, I'll try to troubleshoot it myself, but since I'm currently working to upgrade this particular app to the intranet and this seems to be isolated to a single user and the manager thinks he has a solution, that may not be an overriding priority. Thanks for the help, Jeff, and if I do come across the reason behind it or a reasonable solution, I'll let you know.

Everything is absolute. Everything else is relative.
 
Just an FYI, this was fixed by changing references to the Screen.ActiveForm from a variable to the method directly. For example, instead of this:

Set originalform = Screen.ActiveForm
OriginalFormName = originalform.Name

If RecordInvalid(OriginalFormName) Then
GoTo OpenFormWithCloseExit
End If


it was changed to:

'Set originalform = Screen.ActiveForm
'OriginalFormName = originalform.Name

If RecordInvalid(Screen.ActiveForm.Name) Then
GoTo OpenFormWithCloseExit
End If


and this appears to work fine. Apparently this has happened on other users machines and this fix has worked every time. However, I am at a temporary loss as to how to explain why it should be this way. It appears to only happen on some machines, not all, but usually in the case of upgrades. Since I don't know all of the circumstances of the others, I cannot do further research in this direction. It won't be a problem once I get the upgrade in place (this year?), but I am curious as to why it should be this way. Jebry's explanation from yesterday makes some sense as to a possible cause, but not certain. Can anyone else offer a reason for this? TIA.

Everything is absolute. Everything else is relative.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top