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

What is the best way to prevent a subform from being updated before the main form?

Seth Schrock
Expert 2.5K+
P: 2,951
I have a form, frmCustomer, that has a subform, sfrmFileTypes. My problem is that when I'm entering a new customer and the CustomerID is still blank, I don't want the subform to have any data put into it because it then gets assigned to the customer with the blank CustomerID. I know that if I just fill out the main form first and then go to the subform, everything will work fine. I just want to block it so that it is impossible to update the subform without the CustomerID field being populated.

Here are the relevent fields in the tables behind the two forms:
tblCustomer
CustomerID
CustomerName

tblFileTypes
FileTypeID
CustomerID
FileName

The control names on the forms are the same as the field names FYI.

I just want to know the best way to do this as I'm sure that there are a few options. I could probably do something like the following in the before update event on the subform:
Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me.CustomerID) Then
  2. Me.Form.AllowEdits = False
  3. End If
Although, I don't think that there is a before update event for subforms. I really don't want to write code similar to the above for every control in the subform.
Nov 1 '11 #1

✓ answered by NeoPa

I would have some code in your Form_Current() event handler that determines the state of Me.NewRecord and sets the .Enabled property of the Sub-Form control based on that. Something like :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     With Me
  3.         .SubFormControl.Enabled = (Not .NewRecord)
  4.     End With
  5. End Sub

Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,707
I would have some code in your Form_Current() event handler that determines the state of Me.NewRecord and sets the .Enabled property of the Sub-Form control based on that. Something like :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     With Me
  3.         .SubFormControl.Enabled = (Not .NewRecord)
  4.     End With
  5. End Sub
Nov 2 '11 #2

Seth Schrock
Expert 2.5K+
P: 2,951
That is exactly what I was looking for! Thanks so much.
Nov 2 '11 #3

NeoPa
Expert Mod 15k+
P: 31,707
No problem Seth. Your question was clearly explained, and that makes it so much easier to present appropriate answers :-)
Nov 2 '11 #4

Post your reply

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