Filtered form to datasheet view

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that is opened from a "Find BY" form. I want the user to be
able to click on a button and switch to a datasheet view with the results. I
know that it can be done on the toolbar. The users need it to be "simpler"!
Can someone please help??
 
Hi.
I want the user to be
able to click on a button and switch to a datasheet view with the results.

Create a command button on the form you want to switch to datasheet view.
In the button's OnClick( ) event, place the following code:

Private Sub DataShtBtn_Click()

On Error GoTo ErrHandler

RunCommand acCmdDatasheetView

Exit Sub

ErrHandler:

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

End Sub

Change the name of this example's button to your own, then save and compile.
Whenever the button is pressed in Form View, the Datasheet View will appear.
Beware that the size of the form remains the same, so you may need to do
some resizing to display all the data. To do so, use the MoveSize( ) method
(at least in recent versions of Access -- Access 97 used the Move( ) method,
and I don't remember which version afterwards changed to MoveSize( ) first).
For example, if one needed to make the form wider while keeping the position
and height the same, then the following example would resize the form to four
inches wide:

Private Sub DataShtBtn_Click()

On Error GoTo ErrHandler

Const PIXELS_PER_INCH As Long = 1440

RunCommand acCmdDatasheetView
DoCmd.MoveSize , , 4 * PIXELS_PER_INCH

Exit Sub

ErrHandler:

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

End Sub

Just in case the users want to see the data back in the original Form View,
there's no button available while in Datasheet View to toggle the view back.
One way to do this is to allow a double click of the form to activate the
event that changes the view. For example:

Private Sub Form_DblClick(Cancel As Integer)

On Error GoTo ErrHandler

RunCommand acCmdFormView

Exit Sub

ErrHandler:

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

End Sub


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.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)

- - -
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 questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.
 
Thanks Gunny!
Your solution works perfect! Fortunately I don't have to return to form view
or resize any thing. Your help is greatly appreciated. Thank you again.

Neill
 
Back
Top