Reputation: 3030
I'm sure this question has been asked and answered before, but my Google-fu is failing me.
I have a form in which users can select a record via a combo box, which works fine. However, when users delete a record, the record refreshed, or the form opens, it automatically jumps back to the first record in my table. Ideally, I'd like to have it display something along the lines of "please select a record or create a new one," disabling all the other fields. Now, a potential solution is actually naming record number 1 "please select..." and then writing code to disable each one of those fields, but that seems like a less than ideal solution because manually graying things seems wonky. Furthermore, there are no guarantees that future admins with limited Access experience wouldn't accidentally delete that first record. So, my questions are:
1) Is there a better solution? What's a good/standard way of approaching this problem?
2) If not, can I iteratively disable every field on my form? Or do I have to reference each by name?
Thanks in advance for any help!
Edit: as usual, writing up this question has helped me form solutions to it on my own. I realize that I can set Me.AllowDeletions and Me.AllowInsertions to false if it's displaying the first record. However, the fields still aren't grayed out, you can change tabs on my tab control (is there an event handler for that even?) and there's still the issue of creating a silly dummy record. Any thoughts would be appreciated.
Upvotes: 0
Views: 114
Reputation: 91346
You can disable all controls with a loop. It is best if you set the tag property of controls you wish to disable.
For Each ctl In Me.Controls
If ctl.tag = "problem" Then
ctl.Enabled=false
End If
Next
When the form is opened or a record is deleted, you can change the enabled or locked properties as above and make a suitable label visible. I guess you have a button for refresh and it can invoke the same procedure.
Upvotes: 1