By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,248 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,248 IT Pros & Developers. It's quick & easy.

How To: Disable button in subform until new record is created?

P: 2
Regarding command buttons in Access 2007 . . .

Related to a similar thread, http://bytes.com/topic/access/answer...-if-field-null, I have a more basic question, but minimal VBA experience.

I want to keep a command button on a subform disabled until the user enters data into any field-- in other words, enable the button as soon as a record is created and the EncounterID autonumber is generated (which occurs and displays in a hidden field on the form as soon as the user enters data into any other form field).

I've tried dropping this code in various events, including
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current():
  2.  
  3. If Nz(Me!EncounterID,"") = "" Then
  4.      Me!EnrollButton.Visible = False
  5. Else
  6.      Me!EnrollButton.Visible = True
  7. End If
It almost worked-- I have a similar problem as the user in the old thread-- The button is disabled when EncounterID is null, and stays disabled when EncounterID is NOT null. When I toggle between records, the button is finally enabled.

I want the button to become enabled as soon as the EncounterID is written, without having to toggle between records.

Many thanks in advance to anyone who can help!
Mar 14 '12 #1
Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,419
Your code is triggered by the form's Current event, but logically it should be triggered by the form's Dirty event.

Try this :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Dirty():
  2.     Me.EnrollButton.Visible = (Me.EncounterID > "")
  3. End Sub
Mar 15 '12 #2

P: 2
Hi NeoPa,

Thanks so much for your prompt reply! I tried implementing the code as an Event in the subform property. When I compiled the code, the system threw an error: Invalid use of Null.

Access would not let me use the procedure Form_Dirty(), so this is the code I ended up using. The procedure is the default if I go to Form->Properties->Event->On Dirty.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Dirty(Cancel As Integer)
  2.      Me.cmdEnroll.Visible = (Me.EncounterID > "")
  3. End Sub
Other suggestions?
/SclWrkr
Mar 19 '12 #3

NeoPa
Expert Mod 15k+
P: 31,419
You question refers to a sub-form, but doesn't adequately explain where that fits into the situation. I've assumed it was irrelevant, but if it's not (and the failure of your code indicates that might be the case) then you need to explain what, if anything, is on the main form and what, apart from the CommandButton [cmdEnroll], is on the form in the sub-form.

If everything is on the sub-form, as I'd assumed, then your code should have worked. Clearly the situation is more complicated than you've explained.
Mar 19 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.