A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Toggle Between Form & Datasheet View



 
 
Thread Tools Display Modes
  #1  
Old February 2nd, 2009, 07:32 PM posted to microsoft.public.access.tablesdbdesign
Matthew Pfluger[_2_]
external usenet poster
 
Posts: 36
Default Toggle Between Form & Datasheet View

I would like make a toggle button on my form that changes the current view of
the embedded subform between Form and Datasheet view. What is the syntax for
that? Do I run a specific DoCmd.RunCommand?

Thanks,
Matthew Pfluger
  #2  
Old February 2nd, 2009, 08:38 PM posted to microsoft.public.access.tablesdbdesign
Clifford Bass[_2_]
external usenet poster
 
Posts: 1,295
Default Toggle Between Form & Datasheet View

Hi Matthew,

That may not be possible because the view change applies to the top
level form. However here are a couple of untested ideas: 1) Make two copies
of the subform, one with a default view of Form and the other of Datasheet.
Place each into your form, one on top of the other. Make one visible and the
other not. Toggle the visibilities of both when the button is clicked. 2)
Or maybe place just one subform on the form and switch the Source Object
property between each of the subform's names.

Hope this helps,

Clifford Bass

"Matthew Pfluger" wrote:

I would like make a toggle button on my form that changes the current view of
the embedded subform between Form and Datasheet view. What is the syntax for
that? Do I run a specific DoCmd.RunCommand?

Thanks,
Matthew Pfluger

  #3  
Old February 2nd, 2009, 08:54 PM posted to microsoft.public.access.tablesdbdesign
Danny Lesandrini
external usenet poster
 
Posts: 109
Default Toggle Between Form & Datasheet View

Matthew:

I'm currently using this code to do what you describe. It could be improved,
but it's a good starting place.

Put a button on the parent form, like mine, named cmdOfficesSubformView.
In the On_Click event, I call a proc named ToggleSiteOfficeView() and pass
the view state... datasheet or form.
I'm also reading/writing to the registry so the system remembers how the
user last viewed it and I call the ToggleSiteOfficeView at form open.

Hope this gets you started.


Private Sub cmdOfficesSubformView_Click()
On Error GoTo Err_Handler

With cmdOfficesSubformView
If .Caption = "View As Datasheet" Then
ToggleSiteOfficeView (acCmdSubformDatasheetView)
Else
ToggleSiteOfficeView (acCmdSubformFormView)
End If
End With

Exit_He
Exit Sub
Err_Handler:
msgbox Err.Description
Resume Next
End Sub


Private Sub ToggleSiteOfficeView(ByVal lngView As Long)
On Error GoTo Err_Handler

If lngView = acCmdSubformFormView Then
Me!SiteOfficesSubform.SetFocus
DoCmd.RunCommand lngView
SaveSetting "PTS", "User Prefs", "SiteOfficeView", acCmdSubformFormView
cmdOfficesSubformView.Caption = "View As Datasheet"

ElseIf lngView = acCmdSubformDatasheetView Then
Me!SiteOfficesSubform.SetFocus
DoCmd.RunCommand lngView
SaveSetting "PTS", "User Prefs", "SiteOfficeView", acCmdSubformDatasheetView
cmdOfficesSubformView.Caption = "View As Form"

Else
' do nothing
End If

Exit_He
Exit Sub
Err_Handler:
Select Case Err.Number
Case 2046
' The command or action 'SubformDatasheetView' isn't available now.
Case 3021
' No current record.
Case Else
msgbox Err.Description
End Select
Resume Next
End Sub
--
Danny J Lesandrini

www.amazecreations.com



"Matthew Pfluger" wrote in message
...
I would like make a toggle button on my form that changes the current view of
the embedded subform between Form and Datasheet view. What is the syntax for
that? Do I run a specific DoCmd.RunCommand?

Thanks,
Matthew Pfluger



  #4  
Old February 2nd, 2009, 09:41 PM posted to microsoft.public.access.tablesdbdesign
Clifford Bass[_2_]
external usenet poster
 
Posts: 1,295
Default Toggle Between Form & Datasheet View

Hi Danny,

Ah... a separate command for changing the subform--did not know that.
Thanks!

Clifford Bass

"Danny Lesandrini" wrote:

Matthew:

I'm currently using this code to do what you describe. It could be improved,
but it's a good starting place.

Put a button on the parent form, like mine, named cmdOfficesSubformView.
In the On_Click event, I call a proc named ToggleSiteOfficeView() and pass
the view state... datasheet or form.
I'm also reading/writing to the registry so the system remembers how the
user last viewed it and I call the ToggleSiteOfficeView at form open.

Hope this gets you started.


Private Sub cmdOfficesSubformView_Click()
On Error GoTo Err_Handler

With cmdOfficesSubformView
If .Caption = "View As Datasheet" Then
ToggleSiteOfficeView (acCmdSubformDatasheetView)
Else
ToggleSiteOfficeView (acCmdSubformFormView)
End If
End With

Exit_He
Exit Sub
Err_Handler:
msgbox Err.Description
Resume Next
End Sub


Private Sub ToggleSiteOfficeView(ByVal lngView As Long)
On Error GoTo Err_Handler

If lngView = acCmdSubformFormView Then
Me!SiteOfficesSubform.SetFocus
DoCmd.RunCommand lngView
SaveSetting "PTS", "User Prefs", "SiteOfficeView", acCmdSubformFormView
cmdOfficesSubformView.Caption = "View As Datasheet"

ElseIf lngView = acCmdSubformDatasheetView Then
Me!SiteOfficesSubform.SetFocus
DoCmd.RunCommand lngView
SaveSetting "PTS", "User Prefs", "SiteOfficeView", acCmdSubformDatasheetView
cmdOfficesSubformView.Caption = "View As Form"

Else
' do nothing
End If

Exit_He
Exit Sub
Err_Handler:
Select Case Err.Number
Case 2046
' The command or action 'SubformDatasheetView' isn't available now.
Case 3021
' No current record.
Case Else
msgbox Err.Description
End Select
Resume Next
End Sub
--
Danny J Lesandrini

www.amazecreations.com

  #5  
Old February 2nd, 2009, 10:45 PM posted to microsoft.public.access.tablesdbdesign
Matthew Pfluger[_2_]
external usenet poster
 
Posts: 36
Default Toggle Between Form & Datasheet View

Yes, thank you! That's exactly what I wanted! Have a great day.

Matthew Pfluger

"Danny Lesandrini" wrote:

Matthew:

I'm currently using this code to do what you describe. It could be improved,
but it's a good starting place.

Put a button on the parent form, like mine, named cmdOfficesSubformView.
In the On_Click event, I call a proc named ToggleSiteOfficeView() and pass
the view state... datasheet or form.
I'm also reading/writing to the registry so the system remembers how the
user last viewed it and I call the ToggleSiteOfficeView at form open.

Hope this gets you started.


Private Sub cmdOfficesSubformView_Click()
On Error GoTo Err_Handler

With cmdOfficesSubformView
If .Caption = "View As Datasheet" Then
ToggleSiteOfficeView (acCmdSubformDatasheetView)
Else
ToggleSiteOfficeView (acCmdSubformFormView)
End If
End With

Exit_He
Exit Sub
Err_Handler:
msgbox Err.Description
Resume Next
End Sub


Private Sub ToggleSiteOfficeView(ByVal lngView As Long)
On Error GoTo Err_Handler

If lngView = acCmdSubformFormView Then
Me!SiteOfficesSubform.SetFocus
DoCmd.RunCommand lngView
SaveSetting "PTS", "User Prefs", "SiteOfficeView", acCmdSubformFormView
cmdOfficesSubformView.Caption = "View As Datasheet"

ElseIf lngView = acCmdSubformDatasheetView Then
Me!SiteOfficesSubform.SetFocus
DoCmd.RunCommand lngView
SaveSetting "PTS", "User Prefs", "SiteOfficeView", acCmdSubformDatasheetView
cmdOfficesSubformView.Caption = "View As Form"

Else
' do nothing
End If

Exit_He
Exit Sub
Err_Handler:
Select Case Err.Number
Case 2046
' The command or action 'SubformDatasheetView' isn't available now.
Case 3021
' No current record.
Case Else
msgbox Err.Description
End Select
Resume Next
End Sub
--
Danny J Lesandrini

www.amazecreations.com



"Matthew Pfluger" wrote in message
...
I would like make a toggle button on my form that changes the current view of
the embedded subform between Form and Datasheet view. What is the syntax for
that? Do I run a specific DoCmd.RunCommand?

Thanks,
Matthew Pfluger




  #6  
Old February 2nd, 2009, 11:12 PM posted to microsoft.public.access.tablesdbdesign
Danny J. Lesandrini
external usenet poster
 
Posts: 263
Default Toggle Between Form & Datasheet View

Clifford, it's not all a bed of roses. My code works, it's true, but I get a lot of
little nit-picky errors I can't track down, thus the complicated ON ERROR
routine. Despite the errors, it seems to do what it claims.
--
Danny J. Lesandrini

www.amazecreations.com


"Clifford Bass" wrote ...
Hi Danny,

Ah... a separate command for changing the subform--did not know that.
Thanks!

Clifford Bass

"Danny Lesandrini" wrote:

Matthew:

I'm currently using this code to do what you describe. It could be improved,
but it's a good starting place.

Put a button on the parent form, like mine, named cmdOfficesSubformView.
In the On_Click event, I call a proc named ToggleSiteOfficeView() and pass
the view state... datasheet or form.
I'm also reading/writing to the registry so the system remembers how the
user last viewed it and I call the ToggleSiteOfficeView at form open.

Hope this gets you started.


Private Sub cmdOfficesSubformView_Click()
On Error GoTo Err_Handler

With cmdOfficesSubformView
If .Caption = "View As Datasheet" Then
ToggleSiteOfficeView (acCmdSubformDatasheetView)
Else
ToggleSiteOfficeView (acCmdSubformFormView)
End If
End With

Exit_He
Exit Sub
Err_Handler:
msgbox Err.Description
Resume Next
End Sub


Private Sub ToggleSiteOfficeView(ByVal lngView As Long)
On Error GoTo Err_Handler

If lngView = acCmdSubformFormView Then
Me!SiteOfficesSubform.SetFocus
DoCmd.RunCommand lngView
SaveSetting "PTS", "User Prefs", "SiteOfficeView", acCmdSubformFormView
cmdOfficesSubformView.Caption = "View As Datasheet"

ElseIf lngView = acCmdSubformDatasheetView Then
Me!SiteOfficesSubform.SetFocus
DoCmd.RunCommand lngView
SaveSetting "PTS", "User Prefs", "SiteOfficeView", acCmdSubformDatasheetView
cmdOfficesSubformView.Caption = "View As Form"

Else
' do nothing
End If

Exit_He
Exit Sub
Err_Handler:
Select Case Err.Number
Case 2046
' The command or action 'SubformDatasheetView' isn't available now.
Case 3021
' No current record.
Case Else
msgbox Err.Description
End Select
Resume Next
End Sub
--
Danny J Lesandrini

www.amazecreations.com



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:33 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.