Back Button for Subforms

CourteJester

New member
Local time
Today, 15:13
Joined
Sep 14, 2004
Messages
7
On my main form i have an Unbound subform that allows me to have any of my other forms in there when i want. The problem i am having is i just put in a "Back" button. Is there an easier way to do this. it works, sorta (it only goes back to one subform). Here is the code for the buttons i have (should i use selectcase instead of "if" statements):

The "Back" Button:

Back is a variable: Dim Back as string

Private Sub cmdBack_Click()

If sbfUnbound.SourceObject = "" Then
MsgBox "You cannot go back.", vbInformation, "Unable to go back."
Else
sbfUnbound.SourceObject = Back
End If

The other buttons that get the Subforms to appear have this example of code:

Private Sub cmdCustomerLookup_Click()

If sbfUnbound.SourceObject = "" Then
Back = "frmCustomerLookup"
ElseIf sbfUnbound.SourceObject = "frmOrder" Then
Back = "frmOrder"
ElseIf sbfUnbound.SourceObject = "frmReceivables" Then
Back = "frmReceivables"
ElseIf sbfUnbound.SourceObject = "frmSales" Then
Back = "frmSales"
End If

sbfUnbound.SourceObject = "frmCustomerLookup"

End Sub



i know this will only go back one subform. anythoughts on how i could have it store all the subforms it has gone through so i am able to go backwards or forwards in order of when they were brought upv? any help would be greatly apreciated.
 
I did somethng like that years ago, i.e. keeping track of the forms opened. I recall that I just kept the names in an array prior to leaving a form. I haven't used that technique in years.

I switch subforms now by allowing user to select the subform to switch to via a combobox of subform names, i.e. setting the subform objectsource on the combo box (if form header) AfterUpdate event if non-null. Very little code involved.
 
I've done this also using the Array method as suggested by llkhoutx.

Using a table could also be another way (pretty much the idea same as a multi dimension array) so that in addition to the subform name you could store the primary key of the last visited record on that form so that the user returns to the same record. Then you could also store also any filters, sorting etc. that was active...
 
The combo box selection method gives the user the greatest flexibility. User can navigate anywhere, not back, back, back or forward, forward, forward.
 
thank you so much for the help. But i fear that i have never used a combo box before, so i wouldn't know the coding behind it. If you would beable to give me an example i would greatly appreciate it.
 
See the attached zipped A2K mdb. Open form MainSwitchboard in the design view.

Look at the following properties of control cboOpenForm:
Row Source Type
RowSource
Column Count
Column Widths
List Width

Then open MainSwitchboard in the View mode and try the combo box. Select the form you want to open.

The order of the values in the RowSource can be changed to suit yourself.

Note that combo boxes often have a table and/or query recordsource with a Table/Query Row Source Type, selectable via clicking the rightmost side of the field, a list of types will display. Multiple columns can be specified (Column count & Column Width must be appropriately specified) and sorted appropriately via query. Only one column is displayed after selection. The first column is column 0, then column 1, etc.

Reference column 3, whether hidden or visible by Me!cboName.column(2) (remember 2 is column 3, 0 is column 1).

This is an elegant, but quite simple, solution to your problem.
 

Attachments

Users who are viewing this thread

Back
Top Bottom