Help with MS Access-2010  VBA  (Or Macro)- Allow user to populate form field based on entry into another form field

TonyMannella used Ask the Experts™


Access 2010

I'm currently developing a time/Expense system in an access database.  What I am trying to do is provide the user the ability to populate a form field if and only a prior form field is populated with the correct data.

I have two fields on my Expense form - 1 is a Expense code ID and the other is Mileage.  What I want to do is if the expense form field has an expense ID related only to mileage (text string is Mileage),  then and only then can they input the mileage amount but cannot enter anything in the Expense amount form field.  And, vice versa, if the user enters the mileage (it auto populates the mileage amount based on an calculation), then they cannot enter anything in the Expense Amount field.  See screen shot attached.  Any help would be appreciated
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I would try an OnEnter event for the 'Amount' field.
Assuming your mileage field is called 'Mileage' and amount field is called 'Amount':

If IsNull(Me.Mileage) Or Me.Mileage="" then    'no mileage entered.  UnLock field
Else    'mileage has data.  Lock Field
End If
TonyMannellaBusiness/IT Analyst


Thanks very much - worked like a charm

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial