RE: How to switch views using command button
- From: "'69 Camaro" <ForwardZERO_SPAM.To.69Camaro@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Mar 2005 08:37:12 -0800
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, acCurViewData***
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 Data*** 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, acCurViewData***
> 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
.
- Follow-Ups:
- RE: How to switch views using command button
- From: Sam Kuo
- RE: How to switch views using command button
- References:
- How to switch views using command button
- From: Sam Kuo
- RE: How to switch views using command button
- From: '69 Camaro
- How to switch views using command button
- Prev by Date: Re: Copying buttons from previous form
- Next by Date: record with a null field doesn't print unless a $0.00 or some amou
- Previous by thread: RE: How to switch views using command button
- Next by thread: RE: How to switch views using command button
- Index(es):
Loading