Command Button Disable/Enable

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
In Access I have a form called f-search-records-by-FTFN (directly below). The "Enter FTFN" field (Name = FTFN_Search) has the code shown below which is triggered on "After Update". So if a user opens the form and enters a filetype/filenumber and either presses Tab or Enter the code runs and the record is loaded into the form. If the user then clicks the "Append Record to Paid Accounts" button that record is appended to the t-paid-accounts table. That's the complete operation.

However, the problem is this. If a user opens the form and clicks the "Append Record to Paid Accounts" without entering a filetype/filenumber into the "Enter FTFN" all of the records in the underlying query are appended to the t-paid-accounts table. (Bad - definitely not what I want to happen)

I want to modify my code to disable the "Appened Record to Paid Accounts" command button on form load. Then re-enable it once the user has entered and filetype/filenumber in the "Enter FTFN" field and pressed Tab or Enter.

Option Compare Database

Private Sub Append_to_t_paid_Click()

DoCmd.SetWarnings False
DoCmd.OpenQuery "q-append-record-TO-t-paid-accounts"
DoCmd.Close acForm, "f-search-records-by-FTFN"
DoCmd.OpenForm "f-paid-accounts", acNormal, acDialog
DoCmd.RunCommand acCmdRecordsGoToLast

1583087130814.png


Example of form when one account is enter and correctly loaded.
1583088222212.png


Hope this make sense and thank you for any help!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Form Open event: Me.NameOfYourButton.Enabled = False (or just set it to false in design).
AfterUpdate event on FTFN: validate entry and Me.NameOfYourButton.Enabled = True if that entry is valid. What does that mean? That's up to you to determine if that's text and no numbers, must begin with a certain character, etc. If it is simply that the field is not null or zls:
If Nz(FTFNcontrolNameHere,"")="" Then <<if true, there is nothing in the control. The opposite test for True would be
If Not Nz(FTFNcontrolNameHere,"")="" Then

Do yourself some favours:
- turn on Require Variable Declaration so that future modules have OPTION EXPLICIT right under OPTION COMPARE. You might want to add it to existing modules and recompile your code. (
- no spaces, special characters (except underscore) in any names.
See
What not to use in names - Microsoft Access tips: Problem names and reserved words in Access
 
Upvote 0

Forum statistics

Threads
1,212,933
Messages
6,110,752
Members
448,295
Latest member
Uzair Tahir Khan

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