Solved

Access - Using option buttons to open forms

Posted on 2007-11-14
5
366 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
  • 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 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