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

Autofilling a subform field

Hi,

I have a subform in a main form.
When I create new records in the subform I would like the Subform.
[Issue Ref] to autofill with the MainForm.[Ref]
It sounds quite simple, but ive been bustin my brains trying to get it
to work with no success.
The LinkChild / Master fields seem to be set up correctly, as only the
subform records for that particular Ref are being shown.
Link Child Field = Issue Ref
Link Master Field = Ref

I just cant get the Subforms Issue Ref to autofill.
Any ideas?
Cheers
Zieshan
Jul 10 '08 #1
5 1768
z.******@gmail.com wrote:
Hi,

I have a subform in a main form.
When I create new records in the subform I would like the Subform.
[Issue Ref] to autofill with the MainForm.[Ref]
It sounds quite simple, but ive been bustin my brains trying to get it
to work with no success.
The LinkChild / Master fields seem to be set up correctly, as only the
subform records for that particular Ref are being shown.
Link Child Field = Issue Ref
Link Master Field = Ref

I just cant get the Subforms Issue Ref to autofill.
Any ideas?
Cheers
Zieshan
Would entering something in the OnCurrent event of the subform similar to
If Me.NewRecord Then Me.Ref = Forms!MainFormName!Ref
work?
Bomfunk
http://www.youtube.com/watch?v=ZH6CYeXioR8
Jul 10 '08 #2
Smashed it - that works!! Nice one cheers for that.

I dont suppose you would know a way to insert the current date
automatically in the Date field?
Jul 10 '08 #3
Actually, it has worked, but has just chucked out a problem.
Whenever I try and create a new record using the new form I get the
error
"You cannot add or change a record because a related record is
required in table ......"
Even though I can create a record, it keeps chucking out this alert.

Would you know what the problem is?

Jul 10 '08 #4
z.******@gmail.com wrote:
Smashed it - that works!! Nice one cheers for that.

I dont suppose you would know a way to insert the current date
automatically in the Date field?
There's many ways to do that. Here's two simple ways of doing that.
They only affect new records.

I open a table in design mode with a field called DF. In the
DefaultValue row I entered
Now()
Any record created will use that default value which can be overwritten

In the control's property sheet of the form you could enter
=Now()
in the DefaultValue property.

If you don't want the time, use Date().

Here's a code way, in the OnCurrent event of a form.
If IsNull(Me.DateFieldName) then Me.DateFieldName = Now()
This will affect both new and existing records.

IF you do use Now() just one caveat. Let's say you want records between
Date1 and Date2.
Where Date Between Date1 and Date2

For some reason you don't get any records for date2. Why? Because
using Date(), the time is midnight. So any records for Date2 with a
time not midnight will not be included. So you need to add a day to
date 2.
Where Date Between Date1 and Date2 + 1
This is only used if the date field is a date with time field.

Ahora Es
http://www.youtube.com/watch?v=3p1P4oYbmbU
Jul 10 '08 #5
z.******@gmail.com wrote:
Actually, it has worked, but has just chucked out a problem.
Whenever I try and create a new record using the new form I get the
error
"You cannot add or change a record because a related record is
required in table ......"
Even though I can create a record, it keeps chucking out this alert.

Would you know what the problem is?
Is the link between the main form and subform Ref? If so, the subform's
Ref value will be the value of the main form's Ref value so there is no
need to do what I suggested. Removed the code and let Access to the work.

Personally, I use AutoNumbers as my primary key. Then when I link to
the tables it's automatically assicated with a computer generated key.
Autonumbers used as keys may have sequence gaps but you don't care about
that if used as a key.

If that is not the problem let us know.
Jul 10 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Rey | last post by:
Howdy all. Appreciate your help with several problems I'm having: I'm trying to determine if the Visit subform (subformVisits) has a new record or been changed, i.e. dirty. The form that...
2
by: ivan | last post by:
I have a form (CustomerImfo) that has a subform within it (order). Within that subform is another subform (OrderDetail). That subform (OrderDetail) is displayed in Datasheet view. When I am...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
1
by: bcreighton | last post by:
I have created a bound subform on an unbound masterform linked together with a common field (A store's identification number) using an unbound combobox on the masterform and an invisible field on...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
18
by: DNK2007 | last post by:
Hi all, How to do autofilling of a web form in firefox using javascript. ie through java script program should do autofilling of the web form. Thanks DNK2007
9
by: Ledmark | last post by:
Hello - I've made a form with a subform of the same table, which is for Dr's notes. On the subform I have the query sorting in decending order and a criteria to enter a patient's name so the last...
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?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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...

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.