Solved

Add command button to form in datasheet view

Posted on 2014-01-09
3
5,251 Views
Last Modified: 2014-01-09
Is it not possible to add a command button to a form in the detail section when the form is open in datasheet view?  If this can be done I must be doing something wrong because it is not showing up.
0
Comment
Question by:SteveL13
3 Comments
 
LVL 12

Assisted Solution

by:pdebaets
pdebaets earned 167 total points
ID: 39768067
No, you cannot add a button to a form in datasheet view. Either convert the form to a continuous form, or put the datasheet in a subform on another form. Then you can add the button to the continuous form or to the parent form containing the subform.
0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 166 total points
ID: 39768076
Nope, no command buttons in datasheet view.

What I generally do is put the datasheet form into another form as a subform.  then put a command button in the main form that will perform some operation on the record selected in the subform.
0
 
LVL 35

Accepted Solution

by:
PatHartman earned 167 total points
ID: 39768164
I also embed all datasheet forms in a main form to give me a header/footer area where I can put buttons and selection combos.  This also solves the problem when you are using a switchboard where you can't directly open a form in DS view since the command is different.  But it causes a different problem in that the where argument of the OpenForm method no longer filters the form's data so you need to use the OpenArgs and add a little code to your Load event.

If you want a button on each line, you have to actually use a different control type such as a textbox.  You can format it to make it stand out and put your code in its click event.  Since most people are used to clicking on hyperlinks to go somewhere on web apps, I usually format my "button" to look like a hyperlink so the user understands that if he clicks on it something will happen.  Of course if you need the field to do double duty, you can't use the click event.  You would then need to use the double-click event for the follow hyperlink action.

Here's another little trick.  If you are still using sizable forms (I am since I don't care much for the tabbed interface), you can make your ds subform resize along with your main form with the following code.
Private Sub Form_Resize()
    Const LeftRightPadding = (0.125 + 0.25) * 1440
    Const TopBottomPadding = (0.25 + 0.375) * 1440
    
    Me.sfrmClient.Height = Me.InsideHeight - TopBottomPadding
    Me.sfrmClient.Width = Me.InsideWidth - LeftRightPadding
End Sub

Open in new window

As you can see it goes into the MAIN form's Resize event.  You will need to play with the numbers to get it to work for your particular form.  You also, obviously, need to change the name of the subform control to match your own.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question