Disabling Buttons not working properly

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I have a bound data entry form with 4 buttons (add record, clear form, update record and delete record).

I have the below code to disable the update and delete records button if the record is a new record. However, it is disabling the update and delete record buttons on records that are not new as well as new records.
What am I missing here?

Code:
Private Sub Form_Current()
  If Me.NewRecord = True Then
    Me.AddRecord.Enabled = True
    Me.ClearForm.Enabled = True
  Else
    Me.UpdateRecord.Enabled = False
    Me.DeleteRecord.Enabled = False
  End If
End Sub

Thank you
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Not sure you can do it that way. You could try integrating the following in your current event, but it might be better to use it as a function in either the form module, or a standard module. The latter would allow you to use it on any form, so that's how I'll present it:
Code:
<code>Public Function NewRec(frm As Form) As Boolean
Dim bolNewRec As Boolean

NewRec = False
<code>bolNewRec </code>= frm.NewRecord
If </code><code><code>bolNewRec </code>= True Then NewRec = True
End Function</code>
and call it thus

Code:
If NewRec(Me) Then 
  Me.AddRecord.Enabled = True
  Me.ClearForm.Enabled = True
Else
   Me.UpdateRecord.Enabled = False
   Me.DeleteRecord.Enabled = False
End If
This is untested and I may have erred by using boolean instead of integer. Try it and see.
 
Last edited:
Upvote 0
Hello,

I tested your code and it is still disabling the update and delete records for existing and new records.
 
Upvote 0
Wrong forum :oops:
 
Last edited:
Upvote 0
Your original code should work I think.
You might need to say more about this form, as probably it has to do with the way you have designed it - possibly what you think is a new record is not really new, or vice versa.
 
Upvote 0
Xenou,

That's what I thought too.
Well it is a bound form to allow the user to scroll through records within the Data Entry Form.
There is RefID text box that is auto-generated that I have included on the form for referencing.
There are a variety of combo boxes, text boxes, check boxes, list boxes, and 1 hyperlink text box.

The First three rows in the full form code are:
Code:
Option Compare Database
Option Explicit

Private blnGood As Boolean

I'm using the Private blnGood As Boolean in order to stop bound forms from updating automatically.

Is there anything else you need to know about the design of the form?
 
Upvote 0
Hello,

I see what I did wrong. I have 4 buttons and each of them had to be one way in the first if statement portion and then opposite in the second if statement portion.
The original code I had was incorrect.

Code:
Private Sub Form_Current()
If Me.NewRecord = True Then
    Me.AddRecord.Enabled = True
    Me.ClearForm.Enabled = True
    Me.UpdateRecord.Enabled = False
    Me.DeleteRecord.Enabled = False
Else
    Me.AddRecord.Enabled = False
    Me.ClearForm.Enabled = False
    Me.UpdateRecord.Enabled = True
    Me.DeleteRecord.Enabled = True
End If
End Sub

Thank you
 
Last edited:
Upvote 0
Good. Yes, that seems obvious now - should have seen that too.
 
Upvote 0
Believe it or not, I considered that but didn't translate
it is disabling the update and delete record buttons on records that are not new as well as new records
to mean that it wasn't un-disabling buttons that were already disabled. I guess sometimes I'm just too literal.
 
Upvote 0
It was a "Duh!" moment for me, LOL. Thanks for the help though. You both have helped me out so much throughout my project. :)
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top