Auto Fill Control

  • Thread starter Thread starter greenface via AccessMonster.com
  • Start date Start date
G

greenface via AccessMonster.com

Hi all,

I trying to autofill a control with the value from another control. After
which I would like to lock the original control so that it may not be altered
anymore, but the second control can be altered from then onwards. Currently
I can auto fill using the original value but cannot automate locking
afterwards.
 
I would assume you are doing something like
Me.Control2 = Me.Control1
or the Default Value of Control2 is Control1.

Since you don't say, I will assume you are entering a value in Control1
which then autofills Control2. Do the following in the After Update event of
Control1

Me.Control2 = Me.Control1
Me.Control2.SetFocus
Me.Control1.Locked = True
Me.Control1.Enabled = False

You will also need to reset for each record, so in the Form Current Event.

Me.Control1.Locked = False
Me.Control1.Enabled = True
 
You'll have to add the same code in 2 places...
the AfterUpdate event of Field1 and the OnCurrent event of the form itself.

If Not IsNull(Field2) Then
Field1.Locked = True
Else
Field1.Locked = False
End if

or...
Field1.Locked = Not IsNull(Field2)
 
Thanks for your help. This almost works however when I go back into the same
entry later on I can still alter Me.Control2 by updating Me.Control1.

Can this be set so that when Me.Control2 has a first entry it can longer be
updated by Me.Control1

I would assume you are doing something like
Me.Control2 = Me.Control1
or the Default Value of Control2 is Control1.

Since you don't say, I will assume you are entering a value in Control1
which then autofills Control2. Do the following in the After Update event of
Control1

Me.Control2 = Me.Control1
Me.Control2.SetFocus
Me.Control1.Locked = True
Me.Control1.Enabled = False

You will also need to reset for each record, so in the Form Current Event.

Me.Control1.Locked = False
Me.Control1.Enabled = True
[quoted text clipped - 3 lines]
I can auto fill using the original value but cannot automate locking
afterwards.
 
I've tried a compbination of both answers but cannot get the control to be
uneditable after being auto filled. Any additional help would be welcome.
Code I've used so far is:

Private Sub Form_Current()

If Not IsNull(Me.iwp_est_start) Then
Me.iwp_baseline_start.Locked = True
Else
Me.iwp_baseline_start.Locked = False
End If

End Sub

Private Sub iwp_est_start_AfterUpdate()

Me.iwp_baseline_start = Me.iwp_est_start
Me.iwp_baseline_start.SetFocus
Me.iwp_baseline_start.Locked = True

End Sub




Al said:
You'll have to add the same code in 2 places...
the AfterUpdate event of Field1 and the OnCurrent event of the form itself.

If Not IsNull(Field2) Then
Field1.Locked = True
Else
Field1.Locked = False
End if

or...
Field1.Locked = Not IsNull(Field2)
[quoted text clipped - 3 lines]
I can auto fill using the original value but cannot automate locking
afterwards.
 
Let me continue to use Field1 and Field2 as an example... easier to work with.

I did forget to add the Field2 = Field1 in the Field1 AfterUpdate, but other than
that, the code works. I tested...

If you say that you fill in Field1 with a value, update Field2 with that value (by
code), and can then change Field1, then there is some other problem other than the code
we're discussing.
(please realize that if you Delete the Field2 contents, Field1 will then become
Unlocked... until Field2 has another non-null value or Field1 is filled in again)

I can think of nothing obvious to suggest from here. Try sending me (web site below -
Contact me) the zipped mdb, if it's not too large. In that email describe where the
problem is... what form... etc..
Post back here if you send, so I'll know to expect it... my spam filters are very
aggresive.
--
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions


greenface via AccessMonster.com said:
I've tried a compbination of both answers but cannot get the control to be
uneditable after being auto filled. Any additional help would be welcome.
Code I've used so far is:

Private Sub Form_Current()

If Not IsNull(Me.iwp_est_start) Then
Me.iwp_baseline_start.Locked = True
Else
Me.iwp_baseline_start.Locked = False
End If

End Sub

Private Sub iwp_est_start_AfterUpdate()

Me.iwp_baseline_start = Me.iwp_est_start
Me.iwp_baseline_start.SetFocus
Me.iwp_baseline_start.Locked = True

End Sub




Al said:
You'll have to add the same code in 2 places...
the AfterUpdate event of Field1 and the OnCurrent event of the form itself.

If Not IsNull(Field2) Then
Field1.Locked = True
Else
Field1.Locked = False
End if

or...
Field1.Locked = Not IsNull(Field2)
[quoted text clipped - 3 lines]
I can auto fill using the original value but cannot automate locking
afterwards.
 
Back
Top