Thanks for looking.
I have an access 2000 database which is quite large & complicated and contains about 70 forms and subforms in total. Opening and closing forms/subforms works fine most of the time, but on the odd occasion a form appears which isn't supposed to. This isn't too much of a problem for users with knowledge of how the system is supposed to work, however i'd like to avoid an inexperienced user encountering something unexpected with the wrong form appearing.
It strikes me that their must be a standard way of controlling opening and closing of forms, in conjunction with setting their visible property, that keeps a database looking professional and which is 100% accurate.
At the moment i use two functions which create a "stack" of form names that have been and are being displayed which is ammended as forms are opened and closed, keeping track of the last form opened, and the previous form(s) to "fall back to" when the current form is closed.
the fucntions are "fpushscreen" for appending form names to the stack and "fpopscreen" for removing names from the stack.
Here's the code:
Public Function fPushScreen(cScreenName As String)
On Error GoTo PushScreen_err
'Check that this screen is not already on top of the stack
If cScreenName = aScreen(UBound(aScreen)) Then
'Yes, its a duplicate, so dont add it
Else
'Pushes a new screen name onto the stack
ReDim Preserve aScreen(UBound(aScreen) + 1)
aScreen(UBound(aScreen)) = cScreenName
End If
Exit Function
PushScreen_err:
ReDim aScreen(1)
aScreen(1) = "frmSwitchboard"
End Function
----------------------------------------------------------------
Public Function fPopScreen(Optional bClose As Boolean = False)
On Error GoTo PopScreen_err
'Hide or close the current form
If bClose Then
If Screen.ActiveForm.Name <> "frmSwitchboard" Then
DoCmd.Close
End If
Else
If Screen.ActiveForm.Name <> "frmSwitchboard" Then
Screen.ActiveForm.Visible = False
End If
End If
'Remove the last element from the stack and displays the screen underneath
ReDim Preserve aScreen(UBound(aScreen) - 1)
DoCmd.SelectObject acForm, aScreen(UBound(aScreen))
Screen.ActiveForm.SetFocus
Exit Function
PopScreen_err:
ReDim aScreen(1)
aScreen(1) = "frmSwitchboard"
End Function
-------------------------------------------------------------------------
Hope this is one that some clever person can get involved in as i know this is simple, but it is not 100% reliable and there must be a better way?
Thanks
Vince
I have an access 2000 database which is quite large & complicated and contains about 70 forms and subforms in total. Opening and closing forms/subforms works fine most of the time, but on the odd occasion a form appears which isn't supposed to. This isn't too much of a problem for users with knowledge of how the system is supposed to work, however i'd like to avoid an inexperienced user encountering something unexpected with the wrong form appearing.
It strikes me that their must be a standard way of controlling opening and closing of forms, in conjunction with setting their visible property, that keeps a database looking professional and which is 100% accurate.
At the moment i use two functions which create a "stack" of form names that have been and are being displayed which is ammended as forms are opened and closed, keeping track of the last form opened, and the previous form(s) to "fall back to" when the current form is closed.
the fucntions are "fpushscreen" for appending form names to the stack and "fpopscreen" for removing names from the stack.
Here's the code:
Public Function fPushScreen(cScreenName As String)
On Error GoTo PushScreen_err
'Check that this screen is not already on top of the stack
If cScreenName = aScreen(UBound(aScreen)) Then
'Yes, its a duplicate, so dont add it
Else
'Pushes a new screen name onto the stack
ReDim Preserve aScreen(UBound(aScreen) + 1)
aScreen(UBound(aScreen)) = cScreenName
End If
Exit Function
PushScreen_err:
ReDim aScreen(1)
aScreen(1) = "frmSwitchboard"
End Function
----------------------------------------------------------------
Public Function fPopScreen(Optional bClose As Boolean = False)
On Error GoTo PopScreen_err
'Hide or close the current form
If bClose Then
If Screen.ActiveForm.Name <> "frmSwitchboard" Then
DoCmd.Close
End If
Else
If Screen.ActiveForm.Name <> "frmSwitchboard" Then
Screen.ActiveForm.Visible = False
End If
End If
'Remove the last element from the stack and displays the screen underneath
ReDim Preserve aScreen(UBound(aScreen) - 1)
DoCmd.SelectObject acForm, aScreen(UBound(aScreen))
Screen.ActiveForm.SetFocus
Exit Function
PopScreen_err:
ReDim aScreen(1)
aScreen(1) = "frmSwitchboard"
End Function
-------------------------------------------------------------------------
Hope this is one that some clever person can get involved in as i know this is simple, but it is not 100% reliable and there must be a better way?
Thanks
Vince