I am creating a database on MS Access currently and was wondering if there was a way to program it to automatically skip over certain fields based on an answer in a previous fields?
Yes, it is possible. For example, if you put the following code in the AfterUpdate
event of the txtLastName
textbox:
If txtLastName = ""
me.txtFieldToBeSkippedTo.SetFocus
End If
By skip, do you mean to hide the field or just tab over it? Either way, you'll probably need to write some custom VBA code to help you solve the problem.
To get you started, look at adding some VBA code to the AfterUpdate event of the field that will determine whether another field is shown. Within the procedure for that event, write code to either hide (.Visible
) or remove from the tab order (I think it's .TabStop
) the controls that you want skipped.
You could equally make it impossible for them to enter data in it by disabling it:
Me.f2.Enabled = False
Me.f2.Locked = True
The lock prevents you from changing data in it. Turning off enable prevents you from entering the field at all. If you both, it will to keep it from greying out the field - which may or may not be what you want.