Command button

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

Guest

please help, i have a command button that opens a form, and it only opens a
form in a form view but i want to make the command button to open the form in
a datasheet view......
 
please help, i have a command button that opens a form, and it only opens a
form in a form view but i want to make the command button to open the form in
a datasheet view......

To open a form in Datasheet view, using code, you must explicitly open
it in datasheet view:

DoCmd.OpenForm, "FormName", acFormDS
 
Lorato said:
please help, i have a command button that opens a form, and it only opens a
form in a form view but i want to make the command button to open the form in
a datasheet view......

The DoCmd.OpenForm method has an optional argument to specify the form view to
use when opening the form. Check the help file for details.

DoCmd.OpenForm "FormName", acFormDS
 
You don't say if you're using a VBA code or a macro. If
you're using VBA, the view is the 2nd argument of the
DoCmd.OpenForm method. So if you want to open it in
datasheet view, the syntax is:

DoCmd.OpenForm "testform", acFormDS

If you're using a macro, just change the View option
to "Datasheet"

Hope that helps!

DBS
 
The command button code is like below, so where actually do i put the code?

Private Sub Command30_Click()
On Error GoTo Err_Command30_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Admin & Finance 2"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command30_Click:
Exit Sub

Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click

End Sub
 
the command button has the following code and where actually do i put the new
code?

Private Sub Command30_Click()
On Error GoTo Err_Command30_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Admin & Finance 2"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command30_Click:
Exit Sub

Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click

End Sub
 
the command button has the following code and where actually do i put the new
code?

Private Sub Command30_Click()
On Error GoTo Err_Command30_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Admin & Finance 2"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command30_Click:
Exit Sub

Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click

End Sub

What you have is the Access wizards style of the coding needed to open
the form.
You could use, in place of all of this:

Private Sub Command30_Click()
On Error GoTo Err_Command30_Click

DoCmd.OpenForm "Admin & Finance 2", acFormDS

Exit_Command30_Click:
Exit Sub

Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click

End Sub

Or, if you wish to retain the wizard generated code style:

Private Sub Command30_Click()
On Error GoTo Err_Command30_Click

Dim stDocName As String
stDocName = "Admin & Finance 2"
DoCmd.OpenForm stDocName, acFormDS
Exit_Command30_Click:
Exit Sub

Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click

End Sub
Because you are not actually using any criteria to open the form, you
can dispense with the stLinkCriteria variable completely.
 

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

Back
Top