Have Form, want button to change to Datasheet View w options

D

dohernan

I have a form to input Records one at a time.
I want to create a button that allows users to see all records in Datasheet
view.

When they press that button I want to give them 3 options-
Sort by Last name, First name, date received
Sort by date Received, Last name, First name
Sort by Date Completed, Last name, First name


Thanks. :)
 
K

Klatuu

Create a separate form in datasheet view.
In the Click Event of the button, open the form.

Add an option group to the current form that will select the sort oder.
Pass the value selected in the option group to the new form in the OpenArgs
argument of the OpenForm method.
In the Load event of the datasheet form, set the form's Order By property
using the value received in the option group.

If Not IsNull(Me.OpenArgs) Then
Select Case Me.OpenArgs
Case 1
Me.OrderBy = "[Last name], [First name], [date received]"
Case 2
Me.OrderBy = "[date received].[Last name], [First name]"
Case 3
Me.OrderBy = "[date completed].[Last name], [First name]"
End Select
End If
 
D

dohernan

I am taking this 1 step at a time.
I created a 2nd Form in Datasheet View, the "spreadsheet".
It opens up correctly, as a datasheet.

When I created a button in the original Form to open the spreadsheet it
opens it in Form View instead of datasheet view.

Help?
Thanks again

The button is basic-
Option Compare Database

Private Sub Command53_Click()

End Sub
Private Sub CommandSpreadsheetOpen_Click()
On Error GoTo Err_CommandSpreadsheetOpen_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Personnel2009Spreadsheet"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_CommandSpreadsheetOpen_Click:
Exit Sub

Err_CommandSpreadsheetOpen_Click:
MsgBox Err.Description
Resume Exit_CommandSpreadsheetOpen_Click

End Sub
 
K

Klatuu

Did you set the Default View of the form to Datasheet?

You can also control that in the OpenForm method.

DoCmd.OpenForm stDocName, acFormDS

Remove the strLinkCriteria and the line that Dims it. You are not using it.
 
L

Larry Linson

DoCmd.OpenForm defaults to opening in Form view, and the value used by
OpenForm overrides what you specified as Default View, so you must use the
acFormDS option, as Klatuu said.

Larry Linson
Microsoft Office Access MVP
 
C

Chegu Tom

Put this behind the button
----------------------
RunCommand acCmdDatasheetView
-------------------


But then the user can't easily get back to form view. I use a doubleclick
event on the first field that will switch between datasheet and form view

-----------------
If Me.CurrentView = 1 Then
RunCommand acCmdDatasheetView
Else
RunCommand acCmdFormView
End If
 
D

dohernan

Thank you, I now have it opening in Datasheet View. :)

I created my Option group of 3 on the original form.

I'm not sure how to pass the values, OpenArgs/OpenForm method where?

Thanks again!
 
D

dohernan

I'm not sure how to send the option Group info to the Opening Args...?

By Last Name, First, Date Received
By Date Received, Last Name, First
By Date Completed, Last Name, First


++++++++
Option Compare Database

Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
Select Case Me.OpenArgs
Case 1
Me.OrderBy = "[Last Name], [First Name], [Received]"
Case 2
Me.OrderBy = "[Received].[Last Name], [First Name]"
Case 3
Me.OrderBy = "[Completed].[Last Name], [First Name]"
End Select
End If

End Sub

Private Sub Open(Cancel As Integer)

End Sub

+++++++++++++
 
D

dohernan

Thanks everyone, I got it to work in Datasheet view like this-

Private Sub CommandViewSpreadsheet_Click()
On Error GoTo Err_CommandViewSpreadsheet_Click

Dim stDocName As String
Dim i As Integer
i = Me.SpreadsheetOptionGroup

stDocName = "Personnel2009Spreadsheet"
DoCmd.OpenForm stDocName, acFormDS, , , , , i

Exit_CommandViewSpreadsheet_Click:
Exit Sub

Err_CommandViewSpreadsheet_Click:
MsgBox Err.Description
Resume Exit_CommandViewSpreadsheet_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top