Hi Secret Squirrel,
Per your first message:
"I tried using the "Me.ShipTo = Null" code but that clears it ...",
this would be an expected result if that code was included in the
Form_Current event procedure. Form_Current runs when you first open a form,
and each time the focus leaves one record and moves to another.
This code is also duplicated in the CurrentEvent of the form as well.
Whenever the same code must be run from more than one event procedure, it is
better to put the code into a new procedure (subroutine or function), and
call this procedure from various places. That way, you only have one
procedure to maintain, not two or more identical procedures.
I would try something like this (Caution -- untested. I have omitted
error-handling for clarity, but you should add error handling):
Private Sub Form_Current()
If Me.NewRecord Then
LockControls (False)
Else
LockControls (True)
End If
End Sub
Private Sub ShippingName_Change
LockControls (False)
UpdateShippingInfo
LockControls (True)
End Sub
Private Sub NameOfComboBox_AfterUpdate()
LockControls (False)
UpdateShippingInfo
LockControls (True)
End Sub
Private Sub LockControls(blnLock As Boolean)
Me.ShipToName.Locked = blnLock
Me.ShipToAddress1.Locked = blnLock
Me.ShipToAddress2.Locked = blnLock
Me.ShipToCity.Locked = blnLock
Me.ShipToState.Locked = blnLock
Me.ShipToZipCode.Locked = blnLock
End Sub
Private Sub UpdateShippingInfo()
If [ShippingName] = True Then
Me.ShipToName = Me.Customer
Me.ShipToAddress1 = Me.BillToAddress1
Me.ShipToAddress2 = Me.BillToAddress2
Me.ShipToCity = Me.BillToCity
Me.ShipToState = Me.BillToState
Me.ShipToZipCode = Me.BillToZipCode
Else
Me.ShipToName = Null
Me.ShipToAddress1 = Null
Me.ShipToAddress2 = Null
Me.ShipToCity = Null
Me.ShipToState = Null
Me.ShipToZipCode = Null
End If
End Sub
Thanks for the history lesson on the cartoon!
Tom Wickerath, Microsoft Access MVP
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
Secret Squirrel said:
Sorry about that again Tom. This code is also duplicated in the CurrentEvent
of the form as well.
Private Sub ShippingName_AfterUpdate()
If [ShippingName] = True Then
Me.ShipToName = Me.Customer
Me.ShipToAddress1 = Me.BillToAddress1
Me.ShipToAddress2 = Me.BillToAddress2
Me.ShipToCity = Me.BillToCity
Me.ShipToState = Me.BillToState
Me.ShipToZipCode = Me.BillToZipCode
Me.ShipToName.Locked = True
Me.ShipToAddress1.Locked = True
Me.ShipToAddress2.Locked = True
Me.ShipToCity.Locked = True
Me.ShipToState.Locked = True
Me.ShipToZipCode.Locked = True
Else
Me.ShipToName.Locked = False
Me.ShipToAddress1.Locked = False
Me.ShipToAddress2.Locked = False
Me.ShipToCity.Locked = False
Me.ShipToState.Locked = False
Me.ShipToZipCode.Locked = False
End If
End Sub
The name "Secret Squirrel" has no significance except that it's been my
nickname since I was a teenager. There used to be an old cartoon called "The
adventures of Secret Squirrel". Since I reminded everyone of that character I
was dubbed the name.