473,386 Members | 1,827 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,386 software developers and data experts.

Mandatory field on subform seems to trip over save action of main form -> advice?

I have a mainform with two subforms. When I change a field on the main form, then click into the subform, I get an error saying I haven't filled out a mandatory field. This pops up 3 times in a row in total. After that, I get to my subform as normal.

If I don't change anything on the mainform, or save before I click in the subform, everything is fine.

So, it looks like the save action that happens before going into the subform, also triggers a save action in the subform. That is unexpected behaviour to me.

Any advice on how to fix this would be welcome. Worst case, I can turn the mandatory field into an non-mandatory field and perform a check myself.
Jan 24 '14 #1
20 1962
jimatqsi
1,271 Expert 1GB
How do you save before you click? Do you click a button that has code behind it? If so, what's in that code? What events are programmed for that button?

Jim
Jan 25 '14 #2
zmbd
5,501 Expert Mod 4TB
also, when you click on the subform, are you attempting to start a new record or are you selecting a current record.
Jan 25 '14 #3
Saving on the main form is just the standard Access behaviour (from my understanding that is: when the record is dirty on leaving the record, Access saves the changes).

When I click in the subform, on an empty record, an event fires that prepopulates some columns for the user (timestamp and user name), the last field on the subform, a comment field, is mandatory and needs to be manually typed in by the user. As stated before, for some reason, it looks like a save action is fired before the user gets the change to type in a comment. This only happens when the main form is dirty.
Jan 26 '14 #4
zmbd
5,501 Expert Mod 4TB
You are making some assumptions here that don't hold true, look at your first post. If there were a save action that was firing and tripping you up, then this would happen every time you attempted to access the subform.

We need to see the code that you are using to pre-populate the subform records, please, click on the [CODE/] button in the toolbar and then cut-n-paste your script between the two [code] [/code] tags.

What I suspect is that when you have a dirty record and select the subform, the code is attempting to execute create and save the subform record; however, because the parent is still dirty from an update point on the related field(s) you are running afoul of the required field protocol. Once the parent table gets a chance to finish updating and clears the dirty status, then your subform code gets a chance to run to completion.

However, when you save the parent record first, there is no conflict for the required related fields
Jan 27 '14 #5
The sub that populates the subform is linked to one of the field's 'On Click' events.

However. I just tested without this code, and that sheds a lot more light on what happens:

1) when clicking the new record the * symbol changes to the > symbol.
2) immediately after that, the record seems to refresh, and
3) the first record on the subform is selected (> in front of it).


Here's the sub the pre-populates my subform fields:

Expand|Select|Wrap|Line Numbers
  1. Private Sub commText_Click()
  2.   '------------------------------------------------------------------
  3.   ' Info commText_Click
  4.   '------------------------------------------------------------------
  5.   ' This sub fills out the comment fields that are already
  6.   ' predetermined, such as the date, the user and the tool it belongs
  7.   ' to. It only does this for:
  8.   ' 1) a new record
  9.   ' 2) that is not being edited (first time you click, or undo)
  10.  
  11.   '------------------------------------------------------------------
  12.   ' Declare variables & initialize
  13.   '------------------------------------------------------------------
  14.  
  15.   If TempVars.Item("HandleErrors").Value = 1 Then
  16.     On Error GoTo Err_Handler
  17.   End If
  18.  
  19.   Dim sProcName As String
  20.   sProcName = "commText_Click"
  21.  
  22.   Dim currentUserID As Long
  23.  
  24.   currentUserID = TempVars.Item("lngUserID").Value
  25.  
  26.   '------------------------------------------------------------------
  27.   ' Core
  28.   '------------------------------------------------------------------
  29.  
  30.   If Me.NewRecord = True And Not Me.Dirty Then
  31.     Me.commDate = Now
  32.     Me.commRequestID = [Forms]![Main Menu].[NavigationSubform]![tblTools.ID]
  33.     Me.commOwnerID = currentUserID
  34.   End If
  35.  
  36.   '------------------------------------------------------------------
  37.   ' Error & Exit Handling
  38.   '------------------------------------------------------------------
  39. Exit_Handler:
  40.   Exit Sub
  41.  
  42. Err_Handler:
  43.   glbErrorHandler (sProcName)
  44.   Resume Exit_Handler
  45. End Sub
Jan 27 '14 #6
zmbd
5,501 Expert Mod 4TB
Of note in the code, the use of the tempvars collection could be simplified:
line 15 could be If TempVars!HandleErrors = 1 Then
Same thought in Line 24 CurrentUserId = Tempvars!lngUserID
Why you even have Line 24 is of some question as you could remove line 24 and change line 33 to Me.commOwnerID = Tempvars!lngUserID and remove line 22

Line 30 ( If Me.NewRecord = True And Not Me.Dirty Then ) just to be sure, you are looking at the subform being dirty and not the parent, true?

I see here, [Forms]![Main Menu].[NavigationSubform]![tblTools.ID] that you are using the newer ACC2010 style nav-control and this some issues as logic in using this control is NOT the same as a late bound tab control as many have assumed. I also now need to understand your form from a slightly differnet angle as using this control adds MANY unique challenges/issues:

So let's take a look at this image (You should read this post for context: http://bytes.com/topic/access/answer...ba#post3763553 ):

It has an outer "Parent" form named "NavigationForm"
It then has a navigationcontrol named "NavigationSubForm"
within this subform-control ther are several forms that are loaded using the NavigationSubformControl-buttons. In this image the "NavigationSubForm" control has the form "frm_loanaccounts" loaded. Unfortunately "frm_loanaccounts" does not have a subform of its own



When you say "main form" are you refering to the parent "NavigationForm" or are you refering to the form loaded within "NavigationSubForm" (which for the above example would be "frm_loanaccounts")

When you say click on the subform are you clicking on one of the NavigationSubformControl-buttons (such as the one that is currently highlighted in the image) or are you clicking on something within the already loaded form within the navigationsubformcontrol (ie: "frm_loanaccounts\subform")?

Something I forgot to as you:
I get an error saying I haven't filled out a mandatory field.
Normally this error will have the name of the field in it, would you please post the EXACT error messages you are receiving - you only need to this once for each different message; however, please post the EXACT title, number, and text of each of the messages if different.
Jan 27 '14 #7
ZMBD,

First of all, thanks for the very extended and informative reply.

Let me try and go over the points you raised.

1) TempVars Notation
You are right about the TempVars notation. This particular sub was written when I was not aware yet of that shorthand notation.

2) Line 30 ( If Me.NewRecord = True And Not Me.Dirty Then ):
Correct, I'm checking to see if the comment field the user clicked on is empty or existing, so it indeed refers to the subform (see explanation below).

3) Form Layout
Yes, I am using the 2010 Navigation Control. I have a main navigation form called [Main Menu]. This is the parent form. On this form I have my controls that load the different menus in my database. For example I have an 'Add' page and an 'Edit' page ([frmEdit]). These get loaded in the NavigationSubForm. The [frmEdit] form contains the subform ([sfrmComments]) that's giving me trouble.

So when I say 'main form' I'm referring to the [frmEdit] that's been loaded in the NavigationSubform.
When I say 'sub form', I'm referring to the subform [sfrmComments] that's placed on the Edit form.

This subform contains the following fields:
[commText], [commDate], [FullName]

4) The exact error message:

'You must enter a value in the 'tblComments.commText' field'

(No title or error number given, it's a warning)

From observing the behaviour without the pre-populating, (see my previous post) it looks like for some reason Access is immediately leaving the field / tries to refresh. With the commText field empty, but the others filled in, this gives a dirty record, and being a mandatory field, a warning message.

4) Sorry for not informing everyone more clearly on the use of the navigation controls.
Jan 27 '14 #8
I've been trying to work around / fix the problem, but I keep coming up empty handed.

On a dirty record on the mainform, a subform apparently always requeries. Standard MS Access requery behaviour results in losing your position in the set (i.e., it moves to the first record).

So the only way I currently see of fixing this, is making sure you never click in the subform while the parent form is still dirty. This would require something like
Expand|Select|Wrap|Line Numbers
  1. If Me.dirty = True Then Me.dirty = false
statement in every control's _AfterUpdate event.

Hopefully, someone on this forum can come up with something better.
Jan 28 '14 #9
zmbd
5,501 Expert Mod 4TB
You still haven't answered:
When you say click on the subform are you clicking on one of the NavigationSubformControl-buttons (such as the one that is currently highlighted in the image) or are you clicking on something within the already loaded form within the navigationsubformcontrol (ie: "frm_loanaccounts\subform")?
Also, please be aware that the navigation form tosses in some really unique issues; however, I have not been able to replicate your issue in my test database. Thus, I suspect you have code somewhere else or you are clicking on one of the navigation buttons that is forcing the subform to either reload or requiery.
Jan 28 '14 #10
I click on the bound text field in the already loaded subform. Note that my subform is located in what in your screenshot is called the frm_loanaccounts. So once you've clicked on the button 'frmEdit', again 'frm_loanaccounts' in you example, you'll see the edit page, which contains a subform.

Let my try explain the behaviour in another way:

If I change something on the frmEdit, and NOT save (either by code or via the save button) and then click inside my sfrmComments, placed on frmEdit, it triggers a requery of sfrmComments.

When the data on frmEdit remains the same OR is manually saved, for example by hitting the save button, and then click into the subform, the requery does not appear.

Silly question: how do I quote a previous post?
Jan 28 '14 #11
zmbd
5,501 Expert Mod 4TB
OK,
Just how are you linking the Parent form to the form in the NavigationSubForm Control?
Jan 29 '14 #12
ZMBD,

Fresh new day, fresh new start. I decided to approach it from a different angle and take your suggestion and look for code somewhere that could set of a reload / requery.

I've found the culprit: in my Form_AfterUpdate event of [frmEdit] I have a CurrentDb.Execute statement. This statement saves the username + time stamp for logging purposes to the same table that is in [frmEdit]'s source. I assume since the form's source has changed, that's what's triggering a requery, including the subform.

I just verified and saved this data to a different table and that solves the reloading. Preferably I would like to keep saving to the original table, but right now, I don't see a way of making that happen.
Jan 29 '14 #13
zmbd
5,501 Expert Mod 4TB
I'm glad you finally found the culprit.
Now instead of changing where you are storing the information, store something in the missing comments during that execute method.

I assume since the form's source has changed, that's what's triggering a requery, including the subform.
I don't think that is the case; instead, what I think you are seeing is the error from the execute method as it has stored the value and there's missing information, you then attempt to move on and finally the correct information is entered/stored. Forms do not normally requery unless told to do so; HOWEVER, the navigationsubform control has some very unusual quirks and it may have caused a requery

I am however, very curious about how you related the fields on the master/parent form to the subform in the NavigationSubform control.

Just to be clear, referring to the image in post#7

Assume (I know (^.-) ) for a moment that:
1) NavigationForm is bound to a record-set with Text29 bound to a field in that record-set. Furthermore the field is related to the Frm_LoanAccounts (say FK_CustomerNumber)
2) NavigationSubForm>Frm_LoanAccounts

(in this example) How are you linking the Master Fields in the parent (NavigationForm) to the Child Fields in the child (Frm_LoanAccounts)
Link Master Fields := Text29
Link Child Fields := FK_CustomerNumber
Jan 29 '14 #14
Thanks ZMBD,

On my parent form (frmEdit), I created a (hidden) field called 'masterfield'. This field contains simply the PK of the data behind the form. Exactly analogue to your description of your NavigationForm.

The child field is set to a field in my subforms' recordsource that is the Foreign key to the PK of the main form. Again very analogue, with the difference that the child field is not a control on the subform, just a field in the recordsource.
Jan 29 '14 #15
zmbd
5,501 Expert Mod 4TB
Then this is not a true Parent/Sub relationship as would be established here:



Which is not something one can do with the ACC2010:NavigationSubForm control that I am aware of.
Attached Images
File Type: jpg Bytes_parent_child_subformlink.jpg (43.8 KB, 516 views)
Jan 29 '14 #16
Mine looks similar, with the exception that my version of 'Employee ID' is not a control, but a field in my version of 'sbfActiveOrder's source. From your screenshot I can't see if that's the case in your example as well.

What my subform does is show all comments (in a continous form) for the record that's open in the mainform.

I'm confused now as to why it would not be a true parent/sub relationship. How can the records link properly if the relationship is not as it should be?
Jan 29 '14 #17
zmbd
5,501 Expert Mod 4TB
That last shot is from the Northwinds Traders Template

Open your Main form that looks like the one in Post #7 in design view.
Now, Show the properties dialog box.
In the dropdown list of this box, select the "NavigationSubForm" (this is assuming that you have not changed the name of the ACC2010:NavigationSubForm control)
Select the data tab.

Compare what you see there to what you see in Post #16

See the difference?



Thus even though the Parent may be the outer form, there's no true Parent-Child established between the two.
This is a quirk in the ACC2010:NavigationSubFormControl.

Now there has to be something else going on here if your loaded subform is only showing the related records in the subform to the record selected in the parent... and that might be part of the reason your required field error was tripping three times.
Attached Images
File Type: jpg Bytes_parent_child_NavCtrl_Nosubformlink.jpg (88.1 KB, 710 views)
Jan 29 '14 #18
Thanks again ZMBD,

These NavigationSubforms are very tricky.. I'm starting to regret a little that I've used them. Let me summarize:

My highest level possible form, contains the title, and all the buttons. I've called this [Main Menu] On this form there is a [NavigationSubform]. This is where each button automatically loads/sends whatever you link to with the [Navigation Target Name] field, that you'll find under the Data tab of each Navigation Button.

Then on the NavigationSubForm a form is loaded, as said, depending on which button the user clicked. This form contains subforms exactly the way you normally would set them up with the screenshot you showed in post 16.


Apart from the code in the parent form that triggered the problem, I can't think of anyting out of the ordinary here.
Attached Images
File Type: png NavButton_Data_tab.PNG (5.4 KB, 424 views)
File Type: png Subform_data_tab.PNG (7.4 KB, 483 views)
Jan 29 '14 #19
zmbd
5,501 Expert Mod 4TB
ok,
Took me a moment to follow (^_^)

MainForm->
...NavgationSubformControl->
......LoadedForm->
.........SubformToLoadedform

It is the SubformToLoadedform that is linked back to MainForm. This makes sense now and is a nice trick to linking the subform to the mainform from within the NavigationSubFormControl as you can not do this with the loadedform in the NavigationSubformControl

If this is correct, then I'll attempt this setup in my test database and see if there's something going on that might also lead to the issues you were seeing.

(Yes, the navigation forms have some regreatable quirks. I've found one where if the database is split, and the mainform has VBA script, then many bad things happen. The solution was to use a control with a Macro that called the VBA script - took me three days to figure that out! (@_@) )
Jan 29 '14 #20
MainForm-> <<--- this is called [Main Menu]
...NavgationSubformControl->
......LoadedForm-> <<-- this is called [frmEdit]
.........SubformToLoadedform <<-- this called [sfrmComments]

I have a 'classic' subform link between the latter two. In other words, the subform is placed on [frmEdit]. The master and childfields are fields in [frmEdit] and [sfrmComments] respectively.

Hope that clears it up! This navigation stuff is slick if it works, but it's very confusing to set up. But then again, this is my first elaborate Access DB. My other experience is mainly in MatLab and MySQL.
Jan 29 '14 #21

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

Similar topics

2
by: origin197511 | last post by:
Hello all... I'm having an issue with MSAccess 2000. I have a Form that holds records of my cartridge loads for a rifle and a subform that lists all groups that have been fired with that load. ...
1
by: Charles Ledbetter | last post by:
I'm missing the mistake. I have a MainForm called frmResources. I have a Second Form and related table called frmFootnotes. I am trying to use it as a subform to the main form appearing in a...
30
by: Shannan Casteel via AccessMonster.com | last post by:
I have a subform named "sbfrmParts" with a list of parts along with the quantity and price. I have used a text box in the subform's footer and set the control source to "=Sum(*)". I set the...
15
by: pl626 | last post by:
In Access 2007, my subform has 3 controls that filter data from queries based on user selections from the preceding controls using the requery macro. It works fine when I have only the subform open....
4
by: AdamOnAccess | last post by:
Here's a strange situation: I'm building an application that contains a One-To-Many relationship, and the application has a main form with a sub form to maintain the relationship for data entry. ...
10
by: thayes5150 | last post by:
I have an access database that uses a subform to display records, one column of which is charge data (currency). My users need to verify the charges against the paper form they are scanned from, so...
1
by: Gordon Padwick | last post by:
I’m still having a problem with using a combo box in a main form to select records to be displayed in a subform. I’ve tried code suggested in several sources, but it doesn’t work. In “Filter records...
4
beacon
by: beacon | last post by:
Hi everybody, I have a main form, frmDeficiency, that has a tab control, deficiencyTabControl, that has a subform, fsubEpisodeDetail, on page 2 of the tab control. I also have a command button...
5
by: CD Tom | last post by:
This is going to be hard to explain and to get you what you need to help me. I have a order form that as the user enters items they should show up in a subform. When the user opens the Order Input...
2
by: wardwebber | last post by:
I'm building a simple database (well, I thought it would be) to record personnel names and phone numbers. Each person could have multiple phone numbers (Home, Office, or Mobile). So to record these,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.