473,425 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

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

Seth Schrock
2,965 Expert 2GB
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

3 1630
NeoPa
32,556 Expert Mod 16PB
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
2,965 Expert 2GB
That is exactly what I was looking for! Thanks so much.
Nov 2 '11 #3
NeoPa
32,556 Expert Mod 16PB
No problem Seth. Your question was clearly explained, and that makes it so much easier to present appropriate answers :-)
Nov 2 '11 #4

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

Similar topics

1
by: Bill Strass | last post by:
Problem: Access main form/subform as front end to SQL Server backend. Add/edit via subforms work fine. Not so with main form. Set up a master-detail form-subform using two views linked from SQL...
2
by: TDIOwa | last post by:
I have a form (frmAppointment) with a subform on it (frmAppointmentsub1). I have placed a command button on the main form which calls the function below from the module. The purpose of this...
2
by: prakashwadhwani | last post by:
I have a (Main) form named : Stocks_Main and a Subform in that named: Stocks_Data The Subform is a continuous form There is a field in the subform called QTY_IN Now ... on the main form i.e....
3
by: wideasleep | last post by:
Hi everyone, I have a subform that is a continuous form. It will have mutiple records that connect to a single record in the main form. I have set this up but running tests show only one record...
0
by: Richnep | last post by:
Hi all,. I have a small issue I would like to resolve with VBA. I have a form which it's fields are bound to a table. Within that form is a subform which is a subtable. Tables relationship...
1
by: ssr61 | last post by:
hi can u help me how to open a sub form with in a main form without opening a new window..... my main form (frm_searchby_Name)consists of text field to enter the address and button when...
2
reginaldmerritt
by: reginaldmerritt | last post by:
Not sure if this is even possible, but i want to select a field in a sub form from a main form. I want to populate a field in the main form with a sub forms field value. eg. me.name =...
1
by: Bob Alston | last post by:
I have a system where many subforms are used. Often the size of the subform had to be larger than could be displayed without scrolling. I set the height of the subform to the typical height...
6
Fspinelli
by: Fspinelli | last post by:
I have a query by form set up. I coded and can get the fields on the form to clear by the click of a button, but how do I make the subform clear, too? The main form has a "Clear" button and in...
14
TheSmileyCoder
by: TheSmileyCoder | last post by:
I have noticed that when I resize the window of my main form, that any subforms that "fall" out of the visible area get closed. Now Access automatically reopens them if I expand the window again,...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.