RE: How to switch views using command button

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Sorry. I'm sitting in the Department of Redundancy Department this morning.
I accidentally pasted in too much code. My first suggestion will still work,
but the following is better, since it leaves out the duplication:

' * * * * Start Code * * * *

Private Sub SwitchBtn_Click()

On Error GoTo ErrHandler

Dim accObj As AccessObject
Dim sFormName As String

sFormName = "frmOrderDetails"

Set accObj = CurrentProject.AllForms(sFormName)

If (accObj.IsLoaded) Then
Select Case accObj.CurrentView
Case acCurViewDesign
DoCmd.OpenForm sFormName, acNormal
Case acCurViewFormBrowse, acCurViewDatasheet
DoCmd.OpenForm sFormName, acDesign
Case Else
' Do nothing.
End Select
Else
DoCmd.OpenForm sFormName, acNormal
End If

CleanUp:

Set accObj = Nothing

Exit Sub

ErrHandler:

MsgBox "Error in SwitchBtn_Click( ) in " & vbCrLf & Me.Name & _
" form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description

Err.Clear
GoTo CleanUp

End Sub

' * * * * End Code * * * *

Again, this code won't work in Access 97.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)


"'69 Camaro" wrote:

> Hi, Sam.
>
> > I wonder if there is such code that allows me to switch between Design View
> > and Form View using a command button?
>
> As Allen mentioned, switching from Design View isn't available on the
> current form. You could only switch from Form View to Design View with the
> command button. To do so, just add the following code to the button's click
> event:
>
> RunCommand acCmdDesignView
>
> Since control events don't occur while in Design View, your command button
> would need to reside on _another_ form in order to switch a particular form
> back to Form View from Design View. You don't mention which version of
> Access you are using, but if this situation is acceptable (i.e., another form
> needs to be open with the button visible while switching is desired), then
> you could toggle the target form from Form View or Datasheet View to Design
> View and back, with VBA code like the following:
>
> ' * * * * Start Code * * * *
>
> Private Sub SwitchBtn_Click()
>
> On Error GoTo ErrHandler
>
> Dim accObj As AccessObject
> Dim sFormName As String
>
> sFormName = "frmOrderDetails"
>
> Set accObj = CurrentProject.AllForms(sFormName)
>
> If (accObj.IsLoaded) Then
> Select Case accObj.CurrentView
> Case acCurViewDesign
> DoCmd.OpenForm sFormName, acNormal
> Case acCurViewFormBrowse
> DoCmd.OpenForm sFormName, acDesign
> Case acCurViewFormBrowse, acCurViewDatasheet
> DoCmd.OpenForm sFormName, acDesign
> Case Else
> ' Do nothing.
> End Select
> Else
> DoCmd.OpenForm sFormName, acNormal
> End If
>
> CleanUp:
>
> Set accObj = Nothing
>
> Exit Sub
>
> ErrHandler:
>
> MsgBox "Error in SwitchBtn_Click( ) in " & vbCrLf & Me.Name & _
> " form." & vbCrLf & vbCrLf & _
> "Error #" & Err.Number & vbCrLf & Err.Description
>
> Err.Clear
> GoTo CleanUp
>
> End Sub
>
> ' * * * * End Code * * * *
>
> This code won't work in Access 97.
>
> HTH.
>
> Gunny
>
> See http://www.QBuilt.com for all your database needs.
> See http://www.Access.QBuilt.com for Microsoft Access tips.
>
> (Please remove ZERO_SPAM from my reply E-mail address, so that a message
> will be forwarded to me.)
>
> - - -
> When you see correct answers to your question posted in Microsoft's Online
> Community, please sign in to the Community and mark these posts as "Answers,"
> so that all may benefit by filtering on "Answered questions" and quickly
> finding the right answers to similar questions. Remember that the first and
> best answers are often given to those who have a history of rewarding the
> contributors who have taken the time to answer questions correctly.
>
>
> "Sam Kuo" wrote:
>
> > Hi,
> >
> > I wonder if there is such code that allows me to switch between Design View
> > and Form View using a command button?
> >
> > Regards,
> > Sam
.



Relevant Pages

  • RE: How to switch views using command button
    ... > I wonder if there is such code that allows me to switch between Design View ... > and Form View using a command button? ... Set accObj = CurrentProject.AllForms ...
    (microsoft.public.access.forms)
  • RE: How to switch views using command button
    ... to design another form just to accomodate the ... > Private Sub SwitchBtn_Click ... > Set accObj = CurrentProject.AllForms ... >>> I wonder if there is such code that allows me to switch between Design View ...
    (microsoft.public.access.forms)
  • Re: Dirty Debating Tactics 1: The Broken.Usenet.Promise
    ... counter to thebaitand switch? ... have taken to make the ID scam legit. ... The Argument from Design has been around since at least the Psalmist's ... One is that Darwin ...
    (talk.origins)
  • Dirty Debating Tactics 1: The Broken.Usenet.Promise
    ... bait and switch scams, the only clear cut, fully documented example of ... counter to thebaitand switch? ... The Argument from Design has been around since at least the Psalmist's ... One is that Darwin ...
    (talk.origins)
  • Re: Need a little design help on my latest project
    ... Ok, going to put myself in harms way, and ask for a little design ... I was experimenting with a phototransistor and used a voice modulated LED ... By using an oscilloscope I discovered that when I switched off the LED ... oscilloscope and the phototransistor amplifier circuit, as I went to switch ...
    (sci.electronics.design)