Approach User Support homepage Approach User Support
Answers to Frequently Asked Questions about Lotus Approach
Examples LotusScripts
Example databases
Links to other Lotus Approach support services

[Return to contents]

Example LotusScript: Go back to the last thing that the user was using (A different response)

Last updated: 10 Nov 2002

Paul Bent writes: You have to use script to get the TS user, this statement will return the username:
  
CurrentDocument.User
 
Where you store this depends on how it will be used later. If it's to be available to scripts then assign it to a global variable. If to be available to macros, calc fields, default creation & mod formulas etc you need to transfer the username to a variable field.
 
You can run a script automatically when the apr opens by placing it in Globals - Initialize but if using later than A97 there's a bug to workaround. You have to:
 
1. Locate the DocumentOpened sub in the Approach object and enter a single comment character '. This avoids the bug where Initialize doesn't run when the apr opens but only when the first event script fires which can be a lot later.
2. In the Initialize sub, test for the name of the apr because it will now try to run when other aprs are opened too.
3. One other (harmless) bug is that having entered or modified code in the IDE and pressed F2 to test compile it, when you close the apr, Initialize will run! It's only a design-time problem but it throws you a bit to perhaps see an error that can only come from Initialize when you close the apr.
 
So if you were assigning the username to a global variable you'd first declare it in Globals - Declarations:

 
Public gstrUser As String
 

Then assign the user name in the Initialize sub:

 
Sub Initialize
 
 On Error Goto ErrTrap
 
 'Check this apr is the active one
 With CurrentDocument
  If .Name = "xyz" Then
   'Store the username
   gstrUser = .User
   'Switch to the opening view etc
   '.......
  End If
 End With
 
 Goto ExitSub
 
ErrTrap:
 Msgbox "Error " & Format$(Err, "#0") & " - message: " & Error$, 16, "System Error"
 Resume ExitSub
 
ExitSub:
 
End Sub

If you need to transfer the user to a variable field, the only way is via the Text property of a fieldbox on the active view. You can run a one off sub at design-time to make the fieldbox invisible. Say you create a variable field named vUser, option text, add it to a form and give the fieldbox an object name of fbxUser. Create a global sub to make it invisible, use the F5 key in the IDE to run the sub then save the apr.

 
Sub sHideCtrl
  CurrentView.Body.fbxUser.Visible = False
End Sub

 
Then the Initialize sub, instead of/as well as storing the username in the global variable, has to switch to the view containing the variable field and set its Text property:
 
Sub Initialize
 
 On Error Goto ErrTrap
 
 'Check this apr is the active one
 With CurrentDocument
  If .Name = "xyz" Then
   'Store the username in a global variable
   gstrUser = .User
   'Switch to view containing the variable field
   Set CurrentApplication.ActiveView = .Name~ Of~ View
   'Store the username in the variable field
   CurrentView.Body.fbxUser.Text = .User
   'Switch to the opening view etc
   '.......
  End If
 End With
 
 Goto ExitSub
 
ErrTrap:
 Msgbox "Error " & Format$(Err, "#0") & " - message: " & Error$, 16, "System Error"
 Resume ExitSub
 
ExitSub:
 
End Sub

 
No there isn't a way to "go back" as such. To a limited extent you could do things like when a user switches view, store the "from view" in a global variable and a generic "back" button can switch to the stored view.

[Return to contents]

© Copyright, JohnBrown, Trademarks, Disclaimer, Acknowledgements.