Save control data

  • Thread starter Thread starter dee
  • Start date Start date
D

dee

From this newsgroup, I was very happy to be able to enable or disable
controls on my form, depending upon whether there was data already entered in
the control. It works very well:
Private Sub Form_Current()
'if cbo_ppt_no control(and any other) has already been selected, lock it;
otherwise leave it unlocked
Me.cbo_ppt_no.Locked = Not IsNull(Me.cbo_ppt_no)
Me.cbo_qstnaire_id.Locked = Not IsNull(Me.cbo_qstnaire_id)
End Sub

What I have noticed, however, is that even when I've populated this control,
it isn't until I navigate to another record that it becomes locked. Is there
a way to make this happen as soon as I populate the control and move on to
another control? I have made a few attempts, but they don't work.

Any help would be greatly appreciated!
 
dee said:
From this newsgroup, I was very happy to be able to enable or disable
controls on my form, depending upon whether there was data already entered in
the control. It works very well:
Private Sub Form_Current()
'if cbo_ppt_no control(and any other) has already been selected, lock it;
otherwise leave it unlocked
Me.cbo_ppt_no.Locked = Not IsNull(Me.cbo_ppt_no)
Me.cbo_qstnaire_id.Locked = Not IsNull(Me.cbo_qstnaire_id)
End Sub

What I have noticed, however, is that even when I've populated this control,
it isn't until I navigate to another record that it becomes locked. Is there
a way to make this happen as soon as I populate the control and move on to
another control? I have made a few attempts, but they don't work.


Use the appropriate line of code in each of the controls'
AfterUpdate event.
 
Thanks for your response.

I actually did try to add code to the individual control's AfterUpdate
event, but wasn't successful.

Would you have any advice on what the code should be?
 
On another note, I am now having problems using the code when I have a
default of, say the text LU at the beginning of the control. In other words,
if the control contains only 2 letters, then don't lock.

I have tried this in my On Current form event - the first line works fine -
the second not at all:
Me.box_no.Locked = Not IsNull(Me.box_no)

Me.txt_ppt_no.Locked = Not Len(Me.txt_ppt_no) = 2

Help! :-)
 
dee said:
Thanks for your response.

I actually did try to add code to the individual control's AfterUpdate
event, but wasn't successful.

Would you have any advice on what the code should be?


The code should be exactly the same as what you used in the
Current event, except that you only need the one appropriate
line for for each control. E.g.

Private Sub cbo_ppt_no_AfterUPdate()
Me.cbo_ppt_no.Locked = Not IsNull(Me.cbo_ppt_no)
End Sub
 
dee said:
On another note, I am now having problems using the code when I have a
default of, say the text LU at the beginning of the control. In other words,
if the control contains only 2 letters, then don't lock.

I have tried this in my On Current form event - the first line works fine -
the second not at all:
Me.box_no.Locked = Not IsNull(Me.box_no)

Me.txt_ppt_no.Locked = Not Len(Me.txt_ppt_no) = 2


This should do that:

Me.txt_ppt_no.Locked = Len(Nz(Me.txt_ppt_no, "XX") <> 2

If that's too cryptic, an equivalent, but longer, statement
is:

Me.txt_ppt_no.Locked = Len(Me.txt_ppt_no) <> 2 _
And Not IsNull(Me.txt_ppt_no)
 
Back
Top