Solved

Access - Using option buttons to open forms

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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