Hiding button in Subform datasheet

drazen

Registered User.
Local time
Today, 03:01
Joined
Jan 28, 2016
Messages
31
Hi,
I have a subform datasheet that lists all invoices and payments for the client displayed in the Parent form. On each row i have a'Print' button to print that invoice. This all works fine. However the print button is also displayed on the 'payment' row (each row is either a payment or invoice). I want to hide the button on the rows that are for Payments.
This is what I have now.

(Amount is the invoice amount field, it is always 0 if there is a payment on that row)

Code:
Private Sub Details_Change()
If Amount > 0 Then
        printbutton.Visible = True
    Else
        printbutton.Visible = False
    End If
End Sub

can anyone help please?
 
I don't believe that Access can distinguish between one button and another in continuous forms or datasheet view. I recall trying to hide a delete button we didn't want on the new record and found the best we could do is make sure it didn't do anything.

One solution to this is to use a textbox as a button. I think the textbox needs to be bound to a field so you would need to add a field to the your table. You can format this to look like a button (or pretty close) and then use conditional formatting to hide; just change it's foreground and background color to match the detail background color. To finish this you will probably want to modify the mouse pointer behavior when it over this textbox.
 
Last edited:
I suspect that inquiring minds want to know how, exactly, do you get a Command Button to appear on a Datasheet View Form when the Form is run?

Linq ;0)>
 
I suspect that inquiring minds want to know how, exactly, do you get a Command Button to appear on a Datasheet View Form when the Form is run?

Linq ;0)>
I didn't think of that when I was writing my answer. The experience I talked of was with continuous forms not the datasheet view. Maybe the OP meant continuous forms.
 
This is my form(s)
the code I used to put the buttons on is

Code:
Private Sub invcopy2_Click()
Dim sInvoiceNo As String
If Me.Amount > 0 Then

    If IsNull(Me.InvoiceNo) Then Exit Sub 
    [Forms]![Event Log].Form.[copyinvno] = Me.InvoiceNo
    DoCmd.OpenReport "copyinvoice", acViewNormal, "", "[Invoice No] = [Forms]![Event Log].Form.[copyinvno]"

End If
End Sub

I need something like 'if amount is zero hide button'

Image1a.jpg
 
As the others have said you can't hide or un-hide a button on a continuous form per record.

As already suggested - What you can do is make an imitation button using a texbox, and use conditional formatting to make it change appearance based on your criteria. You can also enable of disable it on the OnCurrent event to make sure it can't be pressed by mistake, or just ignore the click event if the invoice number is 0.
 
I played with the textbox as button idea in the attached database. I wanted to find out if the textbox has to be bound to a field and I'm happy to report that it's not. A few other things I found out are:

  • I had to set the alternate color in the detail to no color. I think it would be tricky to get this to work with alternate colors.
  • I though I could use the conditional format to disable the textbox button but this negates the colors and makes it visible (greyed out). So you will need to disable the action of the textbox button for the condition in the on click code. No big deai.
  • I use the mouse move events in the text box and detail to change the mouse pointer. This setup could probably be improved.
  • When you click on the textbox that's suppose to be the button it leaves the cursor there. I haven't figure out how to avoid that. Edit: But you could set the focus to something else.
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom