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

Force data entry of Main form AND sub form

RockKandee
89 64KB
I am working with Access 2013 in Windows 8

Due to changes I made to make another form work, I have created myself a new problem with a different form.

I have 2 tables
Table 1 = parent
Table 2 = child

The parent table must have at least 1 child.

On my form, I am trying to figure out how to prevent the main form from closing or going to a new record unless the sub has also created a record.

I have tried numerous methods that have failed.

I have been focused on an event for my close button. Once this is working I will include it with my new record button. I have the form set so these buttons are the only option to close or get a new record.

None of my research has given me enough information to make this work. Every time I try to get an event to look at the sub form I receive the following error....

Error Message: The object doesn't contain the Automation object 'Forms.' You tried to run a Visual Basic procedure to set a proper or method for an object. However, the component doesn't make the property or method available for Automation operations.

'Forms' is replaced with what ever control of the sub form I have tried. This error was from attempting to use an If statement in a macro:
Expand|Select|Wrap|Line Numbers
  1. DCount((([Forms]![MainFormName]![SubFormName].[Forms]![NameofField])<1),1,0)
I have tried to use - IsNull also

Not sure if I should be using an If statement and I know DCount is for tables and queries, but I didn't know what else to try.

I am using
IF "whatever I can think of to try"
then message box
then go to control (the one I want filled in on the sub form, though I don't care where it goes)
Else close form

I am using macros.

I would love some insight...

Thanks for all of the help so far.
Dec 19 '13 #1
17 8842
xzorxx
12
Hi ,I didn't get what you wan't really but what I have understand
is that you trying to
when create new record in the main form sub form get a new record
and actually I can't see where is the problem is
ms access will make new record when you make one on the main
you can try to make query then create form to it ,and that's it.
Dec 19 '13 #2
RockKandee
89 64KB
My access form is not creating a new record in the sub form unless I enter data in the sub form.

If data is entered in the main form and then the form is closed (or goes to a new record) before entering anything into the subform, then I have no child record in table 2 related to the record created in table 1.

I would like to know how this works for you.

Thanks
Dec 19 '13 #3
xzorxx
12
can you please tell me what are you using, table to form or query to form ??
if it's query to form I believe that there is problem in your query can you write what did you do..@!
Dec 19 '13 #4
zmbd
5,501 Expert Mod 4TB
xzorxx :
ms access will make new record when you make one on the main
you can try to make query then create form to it ,and that's it.
This is not exactly true, just because the parent has a record does not mean that the the child will have a related record.

xzorxx :
can you please tell me what are you using, table to form or query to form ??
if it's query to form I believe that there is problem in your query can you write what did you do
More than likely this has absolutly nothing to do with the query what so ever.

xzorxx, just exactly how much experience you have with Access?


@RockKandee
IN the before update, check for "new record" and set a flag at the form declarations (the very top of the form's code).
In the afterupdate event of the parent form, if the flag was set have the code either open a recordset or use the "INSERT" db.execute method.

It's quite late here in the states or I'd bash you some code and an example; however, it's time for my nap, I just don't function well w/o 3 or 4 hours of sleep a day (I've made at least a dozen typos already).
Let me get that and clear my desk in the morning. ADezii may be along here in a moment, I sware "A" can just exhale and the code will write itself for him! d(^_^)b
Dec 19 '13 #5
NeoPa
32,556 Expert Mod 16PB
I'm struggling to understand exactly what it is you're trying to achieve here. You mention that a sub record isn't created when you create the main record, but not why that would surprise you. That seems to be standard behaviour with sub-forms. Any time you attempt to move focus away from the main part of the form (which includes pages - or tabs - but not any sub-forms, whether these are found on pages or on the main form itself) the main record will be saved - unless you abort that in your code. If you abort it, of course, you also abort the focus change.

I hope some of this helps you to understand why things aren't behaving as you'd like, but I'm still a bit confused so we'll just have to see.
Dec 19 '13 #6
zmbd
5,501 Expert Mod 4TB
Neopa,
I am Guessing here.
Take a situation I have in the lab.
When I receive a new item, the parent table has a record generated that has the details (serial, lot etc) and related information. The child table has to have the record created that has today's date and the fact that the item was received.
Dec 19 '13 #7
NeoPa
32,556 Expert Mod 16PB
I get the idea of related tables, Z. What I'm struggling to understand is the precise problem as reported. There seems to be some sort of expectation that both related records might be created at the same time somehow, but exactly what is required or expected is unclear to me.
Dec 19 '13 #8
zmbd
5,501 Expert Mod 4TB
RockKandee
in your court.
Dec 19 '13 #9
RockKandee
89 64KB
I understand that the way the form is behaving is normal.

I understand that as soon as a record on the main form is created, it will be saved in the table. I am not trying to prevent the save of the main form record.

I am trying to prevent the close of the form or moving to a new main form record unless the subform has a record created.

I would like to force the user to create a record in the subform before the user can go to a new record on the main form or close the form.

This could be as simple as auto filling in the main forms ID number into the subform on an after update event on the main form.

I am not sure how else to explain.

Thanks for your help :D
Dec 19 '13 #10
RockKandee
89 64KB
When a field is required in a table, then the form will not save the record if the required field is blank.

I want to require that a subform record has been created (by the user) or the form will not close (or go to new record).

Thank you Z for trying to explain for me. *:
Dec 19 '13 #11
zmbd
5,501 Expert Mod 4TB
On Parent:
Before update event:
Check for new record
(optional)Validate the entries if needed
(optional)Confirm parent record entry is intended
Set variable at module/form level that new record was created, I use PK value for the new record.

Afterupdate event
Check if the module/form level variable has a value>0 and if so then simple insert SQL to insert a new record into the child table with the value from the variable, set the variable back to a 0 or negative value, and requery the subform, set the focus to the first field/control in the subform.
Dec 19 '13 #12
NeoPa
32,556 Expert Mod 16PB
Thanks Kandee. That's clearer now :-)

You can stop the form closing by using the Form_Unload() event procedure and setting Cancel=True.

I'm not sure there is a way to stop the focus moving from one record to another. You could use Form_Current() to see if it has done and then go back. That would be a way to handle it. Not too clean, but workable.
Dec 20 '13 #13
RockKandee
89 64KB
Thanks zmbd and NeoPa.

I am trying to work out what you both are saying so I can apply it.

I have been trying to figure out how to search for new record for 2 days now. I am feeling very blond, well I am , so I should, but still feeling like a bit too much bleach soaked into my head. LOL

I will keep at it. Thanks for your help. One of these days I will actually ask a clear question.
Dec 20 '13 #14
RockKandee
89 64KB
My temporary solution until I can figure out the above information....

I have a form for the 2 tables that doesn't allow new records.

I added a pop up form that closes this form and opens a form described below using no subforms.
When this form is closed successfully, it re opens the previous form where the user can then add information to the new records created in the pop up form.

POP UP Form
I selected the one required data entry field from each table
Plus Id fields - Table 1 - primary key / table 2 - primary key and foreign key from table 1
Keys are hidden on the form leaving only Table 1 Name field and Table 2 Type field visible.

I set the form so the only option for closing or going to a new record is to use buttons added to the form.
Form - Format - Navigation Buttons - No
Form - Format - Close Button - No
Add Button - ctrlNewRecord
Add Button - ctrlClose

The Close Button:
Expand|Select|Wrap|Line Numbers
  1. ctrlClose button - Event - On Click - Macro
  2. If - IsNull([Type]) Then
  3. GoToControl - Control Name - Type
  4. MessageBox - Type cannot be left blank
  5. Else
  6. CloseWindow
  7. OpenForm
  8. EndIf
  9. If - IsNull([Name]) Then
  10. CloseWindow
  11. OpenForm
The New Record Button:
Expand|Select|Wrap|Line Numbers
  1. ctrlNewRecord button - Event - On Click - Macro
  2. If - IsNull([Type]) Then
  3. GoToControl - Control Name - Type
  4. MessageBox - Type cannot be left blank
  5. Else
  6. GoTo Record - New
  7. If - IsNull([Name]) Then
  8. GoTo Record - New
This prevents the form from closing or going to a new record
IF the Type field is empty
UNLESS no record was created in Table one (No Name entered).

I am going to keep attempting using zmbd's and NeoPa's suggestions and will update when I have it working. Until then, if anyone else figures this out and can dumb it down for me, that would be awesome!
Dec 20 '13 #15
zmbd
5,501 Expert Mod 4TB
I have a few family obligations here; however, once I get those done I'll bash something togeither for you to look at...
Dec 20 '13 #16
zmbd
5,501 Expert Mod 4TB
here's a fish...

ACC2010 format

ON open the parent form should open.

THe three buttons at the top for record movement are not foolproof, yet they work fairly well and the add new will take you to the new record entry.

Here's what happens, current record, it calls the buttons and the buttons call the code too.
UPon new, the focus shifts to the first name.
Now if the user dirties the controls (these are bound) then the before update event triggers. IF they select yes then the parent record is saved, the child record created and the focus is set on a control within the subform.

I've tried it several times and it appears to work, has a few more bells and whistles than I had intended...
good night.... time for somzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Attached Files
File Type: zip BytesThread_953656_createchildrecord.zip (112.2 KB, 289 views)
Dec 21 '13 #17
RockKandee
89 64KB
Hope you had sweet dreams. Thank you! I am in process of dissecting my fish now. You're the best.
Dec 21 '13 #18

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

Similar topics

3
by: JC Mugs | last post by:
I need help with a project, that has two things driving me crazy. 1. I have number entries that wish to have the data enter from the right, so that when you type in 80, it is .80 or eighty...
15
by: PC Datasheet | last post by:
I have a form with an unbound combobox at the top and seventeen controls below it. Is there a simple way to prevent data entry in any of the controls until a selection is made in the combobox? ...
1
by: jhutchings | last post by:
Hello all, I have a form I designed for data entry. However, when I set the form properties to Data Entry mode, the form completely disappears for Access 2000 users. All they see is a white blank...
2
by: Monroeski | last post by:
I'm not a new user to Access, but I have been away from it for a while, so I'm making a lot of new user mistakes. I have a continuous form set up which displays performance measures for different...
4
by: wideasleep | last post by:
Hello, I have a situation where I have been asked to combine two tables and make a form to continue to enter data. I have created a relationship between the tables and have gotten to creating the...
6
by: VBANovice | last post by:
HI!!! I am in the process of building an Accounting Database. I have two tables. The first table is the Journal Entry Header and the second table contains the Journal Entry Details (the accounts...
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
4
by: jacc14 | last post by:
I have created a form and from the main menu I click a button and it opens my form so I can enter new records. The Data Entry is set to true so that i can do this. I would like to use the same...
1
by: Umesh Bane | last post by:
I have made the form with unbound textboxes and comboboxes. after filling the data in the text boxes by user, with the command button called 'add records' the records are transfer to the...
2
by: yaozaah04 | last post by:
Hello, I am working on a data entry form using Microsoft Access 2010 and I am supposed to give the user a separate option to look for a duplicate record. However the duplicate record-checking works...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.