Code Problem

S

Sandy

I have the following :

Form - 'frm_Contact_Complete'
with - 'txtDateRequired'

Subform - 'subfrm_Job_Complete'
with - 'txtReadyOn' and 'txtWhyDelayed'

and the code :

"Private Sub txtReadyOn_AfterUpdate()
If txtReadyOn > Forms!frm_Contact_Complete.txtRequiredBy Then
Me.txtWhyDelayed.Visible = True
Me.lblWhyDelayed.Visible = True

Else
Me.txtWhyDelayed.Visible = False
Me.lblWhyDelayed.Visible = False
End If
End Sub"

The code works up to a point - the textbox 'txtWhyDelayed' is hidden after
the 'txtReadyOn' is updated (with a date later than that in 'txtRequiredBy')
but when the form is closed and re-opened the 'txtWhyDelayed' is visible
again.

Ideally I would like 'txtWhyDelayed' to remain invisible all of the time
unless the date in 'txtReadyOn' is later than that in 'txtRequired'.

How can I achieve this?

Sandy
 
R

Rod Plastow

Hi Sandy,

The reason the textbox is visible on reopening your form is that it reverts
to the setting you defined in form design view.

Personally I would write a Sub called something like SynchroniseWhyDelayed.
Put your If Then - Else - End If code in this Sub. Now invoke the Sub from
the txtReadyOn_AfterUpdate event as before but also invoke it from the form
load or open event. You may have to enhance your code to cater for nulls in
either of the date fields.

Regards,

Rod
 
L

Linq Adams via AccessMonster.com

Standard procedure is that when you set formatting (such as visibilty or
enabled state, or text/back color) based on a control's value in the
AfterUpdate event, you also have to place the same code in the Form_Current
event so that the formatting for a given record will be correct when moving
between records. This will also address the problem you've encountered when
re-opening the form.
 
M

mustang2

Sandy said:
I have the following :

Form - 'frm_Contact_Complete'
with - 'txtDateRequired'

Subform - 'subfrm_Job_Complete'
with - 'txtReadyOn' and 'txtWhyDelayed'

and the code :

"Private Sub txtReadyOn_AfterUpdate()
If txtReadyOn > Forms!frm_Contact_Complete.txtRequiredBy Then
Me.txtWhyDelayed.Visible = True
Me.lblWhyDelayed.Visible = True

Else
Me.txtWhyDelayed.Visible = False
Me.lblWhyDelayed.Visible = False
End If
End Sub"

The code works up to a point - the textbox 'txtWhyDelayed' is hidden after
the 'txtReadyOn' is updated (with a date later than that in
'txtRequiredBy') but when the form is closed and re-opened the
'txtWhyDelayed' is visible again.

Ideally I would like 'txtWhyDelayed' to remain invisible all of the time
unless the date in 'txtReadyOn' is later than that in 'txtRequired'.

How can I achieve this?

Sandy
 

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