Datasheet View & If Then Statement (1 Viewer)

Ilovexfiles

Registered User.
Local time
Today, 14:10
Joined
Jun 27, 2017
Messages
37
Hi all

I have a form that displays in datasheet view.

I have a code that disables other controls when one control option is selected.
When I am doing data entry on one record in datasheet view, it works well but applies the condition to all of the records/rows.

How do I limit this code to meet the conditions on a record by record basis? (instead of disabling entire columns in the datasheet)

Here is the code:
Private Sub AgencyOpened_AfterUpdate()
If Not IsEmpty(Me.AgencyOpened) Then
Me.PRFReasonforClosing.Enabled = True
Me.DatePRFReasonForClosing.Enabled = True
Me.NotOpenedReason.Enabled = False
Me.DateNotOpenReason.Enabled = False


Else
Me.NotOpenedReason.Enabled = True
Me.DateNotOpenReason.Enabled = True
Me.PRFReasonforClosing.Enabled = False
Me.DatePRFReasonForClosing.Enabled = False

End If

End Sub

Thanks!!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:10
Joined
Aug 30, 2003
Messages
36,123
Won't work with code, as you've seen. Try Conditional Formatting, on the ribbon. As long as those are textboxes you should be able to control the enabled property for each record that way.
 

isladogs

MVP / VIP
Local time
Today, 22:10
Joined
Jan 14, 2017
Messages
18,209
Change it from datasheet to a continuous form.
These are much more adaptable.

Then an after update event in one field will modify other fields as you want to do.

NOTE: You can easily make a continuous form look like a datasheet if you want to
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:10
Joined
Aug 30, 2003
Messages
36,123
Change it from datasheet to a continuous form.
These are much more adaptable.

Then an after update event in one field will modify other fields as you want to do.

NOTE: You can easily make a continuous form look like a datasheet if you want to

Won't disagree with using continuous, as I don't like datasheet, but it isn't relevant to the problem here. Code-based formatting will affect all rows either way.
 

isladogs

MVP / VIP
Local time
Today, 22:10
Joined
Jan 14, 2017
Messages
18,209
Oops I didn't read the post properly.

Just getting ready for Wimbledon here in the uk and Pbaldy has the advantage
 

missinglinq

AWF VIP
Local time
Today, 17:10
Joined
Jun 20, 2003
Messages
6,423
Also note that your syntax

If Not IsEmpty(Me.AgencyOpened) Then

is incorrect. IsEmpty() indicates whether a Variable has been initialized, not whether a Control, AgencyOpened, in this case, is populated! For this purpose you'd use the IsNull() function.

Linq ;0)>
 

Users who are viewing this thread

Top Bottom