hi4ppl
hi4ppl

Reputation: 625

issue in disabling the textbox in access

I have bellow code :

Private Sub s1_AfterUpdate()
If s1 > 20 Then
MsgBox "Maximum is only 20"
Me.s1= 0
ElseIf s1 = 20 Then
Me.s1_8x12qtty.Enabled = False
End If
End Sub

the issue i'm facing is that when I put value to 20 it will disable the Me.s1_8x12qtty which i'm good with that as that is what I told it to do... but when I create new record in the form it remain disable for the lifetime of the form... means if I don't close the form it will remain disable even if I create new record and the value of s1 is zero.

why this happens i'm confused?

regards

Upvotes: 1

Views: 87

Answers (3)

Johnny Bones
Johnny Bones

Reputation: 8402

Why is this happening? Once you put a value in the textbox that causes it to become disabled, you can no longer update the value. Period. You've put this code in the After_Update event, and that event will never fire again no matter what you do, unless you can somehow reset that control another way.

As Gord stated above, checking the value in the On_Current event (or simply resetting the Enabled property to True in the On_Current event) will allow you to reset the control's status every time you move to a new record.

Upvotes: 0

Rawrcasm
Rawrcasm

Reputation: 95

Try creating another sub to run when creating a new record, or placing this code into the pre-existing sub you may have for the same event:

Me.s1_8x12qtty.Enabled = True

Upvotes: 0

Gord Thompson
Gord Thompson

Reputation: 123474

if I don't close the form it will remain disable even if I create new record

It sounds to me like you need a line of code in the On Current event of the form to check the value of s1 and possibly re-enable the control.

Upvotes: 1

Related Questions