By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Prevent Close Or Update Of Form Or SubForm

100+
P: 135
Heya...

Thanks in advance if you can help... or at least understand my gibberish.

I have 2 tables, let's call them tblBacT and tblBacTData, they are related through the auto number primary key "entryId" in tbleBacT. I have created a form (frmBacT) and sub form (subfrmBacTData) with the sub from in columnar view. Kiddie stuff right? My problem is: I don't want the user to be able to enter data in the sub form and then exit or move on to another record in main form frmBacT. This leaves me with an unrelated record in my tblBacTData. I have spent countless hours trying to either; prevent the sub form from being active until the main form is correctly filled, delete or undo on exit or before update if the sub form has data but the main form is empty, or require fields. The problem with requiring a field, say at the table level, is that there can be any number of combinations to enter. e.g. Of the 8 fields the user may use only 3 one time and maybe 5 diff the next. If this makes sense...HELP

I'm a newb at VB, trying to learn on my own (ouch)... been just googling and piecing in what I can for diff needs.

Thanks
Dec 14 '07 #1
Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,186
Have you tried disabling the subform by default, and only enabling it when the correct conditions are met?
Clearly, whenever the conditions are no longer met, you would need to disable it again.
Dec 14 '07 #2

100+
P: 135
Have you tried disabling the subform by default, and only enabling it when the correct conditions are met?
Clearly, whenever the conditions are no longer met, you would need to disable it again.
Yes...that works...kind of.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.      If Form.NewRecord = True Then
  3.           Me.BacTData_Subform.Form.AllowAdditions = False
  4.      End If
  5. End Sub
  6.  
  7. Private Sub Form_BeforeUpdate(Cancel As Integer)
  8.      Me.BacTData_Subform.Form.AllowAdditions = True 
  9. End Sub
SO after I update on the main form I can enter info into the sub form. I still need to delete/prevent update of the main form if nothing is entered into the sub. The main form and sub form records create one composite real world record. I don't want the user to do just part of the record, exit the form, and have part of a "record" floating about.

Thanks for responding.
Dec 14 '07 #3

NeoPa
Expert Mod 15k+
P: 31,186
I guess you could put your code to handle that (cancel update or move you back to the unfinished record) in the OnCurrent event procedure.
Dec 14 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.