Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access - Using option buttons to open forms

Posted on 2007-11-14
5
Medium Priority
?
372 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 1000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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 earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

609 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