473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,385 developers and data experts.

Cascading Forms.

NeoPa
32,556 Expert Mod 16PB
The following code is a class module with an example of its usage to follow.

Class Module Name=classForm
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. '21/1/2004  Added Private Set & Public Get code for frmTo.
  5. '21/9/2004  Removed ResumeTo functionality. _
  6.             Now handled by the OnTimer() subroutine in the calling form _
  7.             checking for (Visible) which indicates the called form is finished.
  8. '24/2/2005  Added function Uninitialised to show if instance of this object _
  9.             has yet been initialised with the callers info. _
  10.             It also checks this before it tries to open a new form.
  11. '13/3/2007  Added optional parameter varOpenArgs to be passed 'as is' into _
  12.             the new form.
  13.  
  14. Private Const conUnInitMsg As String = _
  15.                   "Object uninitialised - unable to show form."
  16.  
  17. Private frmParent As Form
  18. Private WithEvents frmCalled As Form
  19.  
  20. Public Property Set frmFrom(frmValue As Form)
  21.     Set frmParent = frmValue
  22. End Property
  23.  
  24. Private Property Get frmFrom() As Form
  25.     Set frmFrom = frmParent
  26. End Property
  27.  
  28. Private Property Set frmTo(frmValue As Form)
  29.     Set frmCalled = frmValue
  30. End Property
  31.  
  32. Public Property Get frmTo() As Form
  33.     Set frmTo = frmCalled
  34. End Property
  35.  
  36. 'Uninitialised returns True if frmFrom not yet initialised.
  37. Public Function Uninitialised() As Boolean
  38.     Uninitialised = (frmFrom Is Nothing)
  39. End Function
  40.  
  41. 'ShowForm opens form strTo and hides the calling form.  Returns True on success.
  42. Public Function ShowForm(strTo As String, _
  43.                          Optional varOpenArgs As Variant) As Boolean
  44.     ShowForm = True
  45.     'Don't even try if caller hasn't initialised Form object yet
  46.     If Uninitialised() Then
  47.         ShowForm = False
  48.         Call MsgBox(conUnInitMsg, , "classForm.ShowForm")
  49.         Exit Function
  50.     End If
  51.     Call DoCmd.Restore
  52.     'Handle error on OpenForm() only.
  53.     On Error GoTo ErrorSF
  54.     Call DoCmd.OpenForm(FormName:=strTo, OpenArgs:=varOpenArgs)
  55.     On Error GoTo 0
  56.     Set frmTo = Forms(strTo)
  57.     frmFrom.Visible = False
  58.     Exit Function
  59.  
  60. ErrorSF:
  61.     ShowForm = False
  62.     Call MsgBox("Error found in [" & frmFrom.Name & _
  63.                 ".ShowForm] calling [" & strTo & "]." & VbCrLf & _
  64.                 "Error#=" & Err.Number & " - " & Err.Description & ".")
  65. End Function
  66.  
  67. '************************* Contained Object Method(s) *************************
  68. 'For these subroutines to be activated the contained object must have the
  69. ''On Close' property set to a valid subroutine within the contained object.
  70. Private Sub frmCalled_Close()
  71.     frmFrom.Visible = True
  72.     Call DoCmd.Restore
  73.     Set frmTo = Nothing
  74. End Sub
  75. '***************************************************************************
This code is an example menu form. It is calls another form (A, B & C) and is called by another menu (D & E) so incorporates all the code required to make it work.
It is a standard in my databases that reports are always maximised and that forms are always restored, so there is code in her to do that, but this can be stripped without losing the main functionality.
  1. To use the classForm class it is necessary to Dim a variable to reference it. This need only be declared as Private as it is referenced exclusively internally.
  2. The variable needs to be set up with the calling form [frmFrom] before it is used in anger.
  3. Invokes a new form. This causes the current form to be hidden until the invoked form is closed.
  4. I would typically have a CommandButton on every form to exit.
  5. In case the x at top-right (or any of a bunch of other methods) is used, the actual tidying up work is (and always should be) done in the Form_Close event procedure. A completely empty procedure is simply dropped at compile time, so a comment line must be included here at least. The class can only pick up (and pass on) the fact that the called form has been closed if this procedure exists in the called form.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private clsTo As New classForm                        '<-- A
  5.  
  6. Private Sub Form_Open(Cancel As Integer)
  7.     Call DoCmd.Restore
  8.     Set clsTo.frmFrom = Me                            '<-- B
  9. End Sub
  10.  
  11. Private Sub cmdGroupCust_Click()
  12.     Call clsTo.ShowForm(strTo:="frmGroupCust")        '<-- C
  13. End Sub
  14.  
  15. Private Sub cmdExit_Click()                           '<-- D
  16.     Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Me.Name)
  17. End Sub
  18.  
  19. Private Sub Form_Close()                              '<-- E
  20.     'Method must exist in order for container to handle event.
  21. End Sub
Mar 12 '07 #1
2 8730
Denburt
1,356 Expert 1GB
Nice... BookMarked! Question, how many buttons do you usually run on these forms? I am doing quite well with button management, I have many buttons yet it is neat and tidy but I was curious.
Mar 23 '07 #2
NeoPa
32,556 Expert Mod 16PB
Thank you.
There's not really any limit except the size of the form.
I normally run 1280x1024 resolution but try to design for 1024x768. I run up to seven rows of buttons (Plus my cmdExit button on all forms) and up to two columns. Each button is .8 high and wide and I leave a gap of .2 between each (vertically).

I know I could fit more on, but aesthetically, I want it to be comfortable and easy for the operator to use.
Mar 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kate | last post by:
I am learning VB by working on an existing application. It is dawning on me that this particular program was not designed very carefully, and I have come to the point where I have to deal with...
1
by: JMosey | last post by:
Not sure if this has been covered ( a google search came up pretty bare). I have a site that: - has multi-level cascading menus - floats center of the browser window - Will have fairly heavy...
5
by: Colin Walls | last post by:
I have been asked to produce a web catalogue of services and associated options, this eventually will be used for ordering the services. My initial thought was to use a set of cascading drop...
9
by: (Pete Cresswell) | last post by:
Seems like when there's a 1:1 relationship, the order of referential integrity enforcement depends on which way you drag the mouse pointer when drawing the relationship line. If you drag from...
3
by: Crucifix | last post by:
Hello, I'm writing a small C# app, and part of what I'm trying to do involves the dragging of PictureBox controls on a form. Unfortunately, MouseMove seems to be behaving very oddly, causing...
9
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
4
klarae99
by: klarae99 | last post by:
Hello, I am working on an Access 2003 Database. The tables that pertain to this issue are tblOrg, tblState, tblCity, and tblZip. I have posted the table structure with only the pertinant fields...
8
by: 20028431 | last post by:
This is driving me mad! I have been trying for 3 days now to work out how to do this with no success. I have tables for Customer, Bookings, Entertainment, Act, Agent, and several others. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.