Solved

Access - Using option buttons to open forms

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now