Keep field enabled after closing db

G

Guest

I have a form and subform in which I am enabling and disabling 3 controls in
the subform, based on "Null" criteria in a control on the form. I am using
the following code and it works, except when I close the form and/or
database. When the form or db is closed, the 3 controls on the subform are
disabled regardless if the control on the form is 'Not IsNull'. I want the 3
controls to stay enabled when the other field is 'Not IsNull' I would
appreciate any help. Thanks.

Private Sub dtmFundsReqDt_AfterUpdate()
If Not IsNull(Me.dtmFundsReqDt) Then
Me.fsubExpenses.Form!dtmRequestDt.Enabled = True
Me.fsubExpenses.Form!strExpDescrip.Enabled = True
Me.fsubExpenses.Form!curRequestAmt.Enabled = True
End If

If IsNull(Me.dtmFundsReqDt) Then
Me.fsubExpenses.Form!dtmRequestDt.Enabled = False
Me.fsubExpenses.Form!strExpDescrip.Enabled = False
Me.fsubExpenses.Form!curRequestAmt.Enabled = False
End If
End Sub
 
J

Jeff Boyce

Mary Beth

If your AfterUpdate code sets the controls.Enabled property as desired, you
can "call" that procedure to run any time you want (say, in the form's
OnCurrent event?).

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

Guest

Jeff, thanks for your help, but I am not exactly sure how to write an
OnCurrent event. I looked it up, but am still a little confused how to use
this event property. Could you help? Thanks!
 
G

Guest

First , right now yuor code is placed in the After Update event of
dtmFundsReqDt, so the code will only run after that control is updated. As
Jeff suggested, if you move the code to the On Current event of your form,
then it will run every time a record becomes the current one. If you open the
properties sheet for your form, go to the events tab, you will see "On
Current". Move your code to this event.

Second, you have a little bit of uneccessary coding. you could simplify like
this;

If IsNull(Me.dtmFundsReqDt) Then
Me.fsubExpenses.Form!dtmRequestDt.Enabled = False
Me.fsubExpenses.Form!strExpDescrip.Enabled = False
Me.fsubExpenses.Form!curRequestAmt.Enabled = False

Else
Me.fsubExpenses.Form!dtmRequestDt.Enabled = True
Me.fsubExpenses.Form!strExpDescrip.Enabled = True
Me.fsubExpenses.Form!curRequestAmt.Enabled = True

End If

HTH
 
G

Guest

You guys are brilliant!! Thanks.
--
Mary Beth


Beetle said:
First , right now yuor code is placed in the After Update event of
dtmFundsReqDt, so the code will only run after that control is updated. As
Jeff suggested, if you move the code to the On Current event of your form,
then it will run every time a record becomes the current one. If you open the
properties sheet for your form, go to the events tab, you will see "On
Current". Move your code to this event.

Second, you have a little bit of uneccessary coding. you could simplify like
this;

If IsNull(Me.dtmFundsReqDt) Then
Me.fsubExpenses.Form!dtmRequestDt.Enabled = False
Me.fsubExpenses.Form!strExpDescrip.Enabled = False
Me.fsubExpenses.Form!curRequestAmt.Enabled = False

Else
Me.fsubExpenses.Form!dtmRequestDt.Enabled = True
Me.fsubExpenses.Form!strExpDescrip.Enabled = True
Me.fsubExpenses.Form!curRequestAmt.Enabled = True

End If

HTH
 
G

Guest

Let's simplify your simplification:

With Me.fsubExpenses.Form
!dtmRequestDt.Enabled = Not IsNull(Me.dtmFundsReqDt)
!strExpDescrip.Enabled = Not IsNull(Me.dtmFundsReqDt)
!curRequestAmt.Enabled = Not IsNull(Me.dtmFundsReqDt)
End With
 
G

Guest

Thank you, Beetle, but you under estimate yourself. You code is just fine.
Rather than actually brilliant, I am extremely lazy and love goofing off, so
I have become adept at finding out how to do things with the absolute minimum
effort :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top