Solved

Access - Using option buttons to open forms

Posted on 2007-11-14
5
368 Views
Last Modified: 2008-02-07
 How do I close the current form when selecting a different option button.  I tried to put docmd.close before opening the form but that only works one time and does not allow me to keep switching between forms.  Goal:  
Open form1, close form1 before opening form2.    
open form2,  close form2 before opening form3.
open form3, close form3 before opening form2.
and so on....

form1,2,&3 also have attached sub-forms.


    If grpViewAll.Value = 1 Then
    DoCmd.OpenForm "frmForecast1", acNormal, "qryAdd"

    ElseIf grpViewAll.Value = 2 Then
    DoCmd.OpenForm "frmForecast2", acNormal, "qryAdd"
             
    Else
    DoCmd.OpenForm "frmForecast3", acNormal, "qryAdd"
0
Comment
Question by:SharonInGeorgia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 20282103
try specifying the name of the form to close

docmd.close acForm, "form1"

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 20282107
urm, you might also need to play around with your order possibly
open then close or close then open
cant remember, been ages since I touched access
0
 
LVL 5

Expert Comment

by:sinjin
ID: 20282360
Hi Sharon -
Are you using an option group?
Are these forms different entirely or are you moving between the same three forms?  
Reason I ask is that I would think about changing your code to toggle the visible property on them instead of opening and closing them.  If  you do that then all forms stay loaded in memory so they appear and disappear faster.  Less work for the db engine as well (if your forms are displaying bound data).
-sinjin

PS - code to follow based on your answers :-)
0
 

Author Comment

by:SharonInGeorgia
ID: 20282568
I can combine two of the forms.   If the user selects budget then only the budget months appear.  If they select ALL then all of the budget, forecast and Actual months appears.  These two forms work together becasue the columns are locked.  The other form, however, allows changes and uses a different query.  
0
 
LVL 5

Accepted Solution

by:
sinjin earned 250 total points
ID: 20283919
ok....

here's how I'd tackle this:


in the OnLoad event of the form Open all three forms and hide them.  If you want a default form to show then don't hide that one.

DoCmd.OpenForm "frmForecast1", acNormal, "qryAdd"
DoCmd.OpenForm "frmForecast2", acNormal, "qryAdd"
DoCmd.OpenForm "frmForecast3", acNormal, "qryAdd"

Forms!frmForecast1.visible=false
Forms!frmForecast2.visible=false
Forms!frmForecast3.visible=false



In the AfterUpdate event of grpViewAll
Select Case Me.selectView.Value
   
        Case Is = 1 'Budget Only
            Forms!frmForecast1.Visible = True
            Forms!frmForecast2.Visible = False
            Forms!frmForecast3.Visible = False
       
        Case Is = 2 'Forecast Only
            Forms!frmForecast1.Visible = False
            Forms!frmForecast2.Visible = True
            Forms!frmForecast3.Visible = False
       
        Case Is = 3 'Actual Only
            Forms!frmForecast1.Visible = False
            Forms!frmForecast2.Visible = False
            Forms!frmForecast3.Visible = True
   
   
        Case Is = 4 'All
            Forms!frmForecast1.Visible = True
            Forms!frmForecast2.Visible = True
            Forms!frmForecast3.Visible = True
       
    End Select


Hope this helps,
 - sinjin
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question