views:

36

answers:

3

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?

+2  A: 

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
Robert Harvey
This is a different approach than I had thought, but it looks good.
Ben McCormack
A: 

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.

Ben McCormack
AfterUpdate seems to me to be the only correct event, as OnChange fires with every keystroke.
David-W-Fenton
@David that's a good point. I had forgotten how the *OnChange* event fired.
Ben McCormack
A: 

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.

CodeSlave