enable disable fields and buttons (1 Viewer)

megatronixs

Registered User.
Local time
Today, 02:17
Joined
Aug 17, 2012
Messages
719
Hi all,

I have some code to check if a date is filled in a field, if so, then the button that enters the date in the field are disabled.
The problem I have, it is not doing this on record basis, but on the whole field.
If I have already one record like that filled in, all other records will have the field and button greyed out (disabled)
How can I make it test on a field in the record instead of the whole column?

This is the code that I use when the form loads:
Code:
If Me.final_1st <> "" Then
Me.final_4_eye_1st.Enabled = False
Me.add_qc_1.Enabled = False
Else
Me.final_1st.Enabled = True
Me.add_qc_1.Enabled = True
End If

Actually the field and button are disabled once the button is pressed to create a new QC record, the date is entered and both should be greyed out so they can't be used again.

Any ideas where it could go wrong?

Greetings.
 

missinglinq

AWF VIP
Local time
Yesterday, 20:17
Joined
Jun 20, 2003
Messages
6,423
Is this a continuous form?
From the description it almost assuredly is a Continuous View Form, and this is standard behavior, doing conditional formatting (lower case 'c' and 'f') using VBA code. For a Continuous View Form, this kind of thing needs to be done using Conditional Formatting (upper case 'C' and 'F') off of the menu/ribbon.

Sadly, Conditional Formatting is not available for Command Buttons! The workaround is to use a Textbox, tweaked to look like a Command Button, using its OnClick event to carry out the button's actions, then use Conditional Formatting off of the menu/ribbon to Enable/Disable it, using the 'Expression Is' option for the condition.

The Textbox holding the date needs to be done in the same way.

Linq ;0)>
 

megatronixs

Registered User.
Local time
Today, 02:17
Joined
Aug 17, 2012
Messages
719
Hi all,

I should have been more clear :-(
The fields and buttons are on a subform that has about 20 fields and 10 buttons.
it is not set as a continuous form. the fields on the subform come from another table that is linked with the review_id on review_id on the main table. Maybe this could be the trouble.
The database was created with Access 2003, but I use 2010 to edit it.
I will try with the conditional formating and making the button with a text box and see what comes from it.

Greetings.
 

megatronixs

Registered User.
Local time
Today, 02:17
Joined
Aug 17, 2012
Messages
719
well, conditional formating is not possible as it is set as form and not as datasheet (continuous form) :-(
I guess I need something like: if review_id current selected and that field has date, then grey out.

Greetings.
 

missinglinq

AWF VIP
Local time
Yesterday, 20:17
Joined
Jun 20, 2003
Messages
6,423
...If I have already one record like that filled in, all other records will have the field and button greyed out (disabled)...
The above made it seem as if you could view the Controls in question, in all Records, at the same time, making it seem that you were using a Continuous Form. I'm now assuming that you mean that the formatting persists as you move from Record-to-Record, on a Single View Form.

Conditional Formatting, off of the menu/ribbon, can be used on all types of Forms, but it must be used with Datasheet and Continuous View Forms!

Since this is a Single View Form, to get the formatting to be Record-appropriate, a slight modification of your original code, and moving it to the Form_Current event, will accomplish your goal!

'Empty' Controls in Access are usually Null, not Zero-Length Strings, which is what you're testing for with

If Me.final_1st <> "" Then.

The following will test for Nulls and Zero-Length Strings:

If Nz(Me.final_1st, "") <> "" Then

and your code then becomes

Code:
Private Sub Form_Current()

 If Nz(Me.final_1st, "") <> "" Then
    Me.final_4_eye_1st.Enabled = False
    Me.add_qc_1.Enabled = False
 Else
   Me.final_1st.Enabled = True
   Me.add_qc_1.Enabled = True
 End If
 
End Sub

Note that code like this, placed in the Form_Load event, will only be applied to the first Record that is displayed, when the Form opens...not to all Records, as you desire, here!

Linq ;0)>
 

megatronixs

Registered User.
Local time
Today, 02:17
Joined
Aug 17, 2012
Messages
719
missinglinq, you are my hero :)
thanks a lot for this, it is really great to have help when one loses his way :)

Greetings.
 

missinglinq

AWF VIP
Local time
Yesterday, 20:17
Joined
Jun 20, 2003
Messages
6,423
That's why we're here!

Glad we could help!

Good Luck with your project!

Linq ;0)>
 

Users who are viewing this thread

Top Bottom