473,472 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Loading data into a subform

5 New Member
Hi,

I am trying to load a number of records into a subform "Schedule Codes" from form "Certif" using the followowing code.
[code]Do While Not RS.EOF
With RS
Forms![certif]![schedule codes]![GroupNo] = !GroupNo
Forms![certif]![schedule codes]!
Expand|Select|Wrap|Line Numbers
  1.  = !Code
  2.   Forms![certif]![schedule codes]![Date] = Now()
  3.   Forms![certif]![schedule codes]![GroupNo].SetFocus
  4.   DoCmd.GoToRecord , , acNewRec
  5.   RS.MoveNext                                      
  6.  End With
  7. Loop
  8. RS.Close
  9. Forms![certif].SetFocus
On the first pass data is loaded into the first record of form Schedule Codes but Docmd.GoToRecord , , acNewRec produces a "Can't go to Specified Record" error and subsequent loads overwrite the first record. I have tried to set focus to the subform but get the error "Can't move to the control Schedule Codes". The .SetFocus only seems to work if I enter a field name.

Any help on loadiing data into a subform would be appreciated.
Jul 7 '08 #1
6 5034
MikeTheBike
639 Recognized Expert Contributor
Hi,

I am trying to load a number of records into a subform "Schedule Codes" from form "Certif" using the followowing code.

Do While Not RS.EOF
With RS
Forms![certif]![schedule codes]![GroupNo] = !GroupNo
Forms![certif]![schedule codes]![code] = !Code
Forms![certif]![schedule codes]![Date] = Now()
Forms![certif]![schedule codes]![GroupNo].SetFocus
DoCmd.GoToRecord , , acNewRec
RS.MoveNext
End With
Loop
RS.Close
Forms![certif].SetFocus

On the first pass data is loaded into the first record of form Schedule Codes but Docmd.GoToRecord , , acNewRec produces a "Can't go to Specified Record" error and subsequent loads overwrite the first record. I have tried to set focus to the subform but get the error "Can't move to the control Schedule Codes". The .SetFocus only seems to work if I enter a field name.

Any help on loadiing data into a subform would be appreciated.
Hi

I have more questions than answers, but, on the basis that the code is running in the main (Certif) form, then I think to move to a new record in the sub-form should be (something) like this – may be!

DoCmd.GoToRecord acDataForm, “schedule codes”, acNewRec

As it stands you are trying to move to a new record in the main form.

Looking at Access Help under GoToRecord may help.


HTH


MTB
Jul 7 '08 #2
Ian Norris
5 New Member
Yes I have tried putting the form name into the GoToRecord command but that returns the error The Object "Schedule Codes" isn't open. But it must be open as the first record is loaded. I've tried opening the subform again but, as expected, that opens a new version of the form.
Jul 7 '08 #3
nico5038
3,080 Recognized Expert Specialist
Your fields on the subform should be referenced like:

Forms![certif]![schedule codes].form![GroupNo] = !GroupNo

Check also: http://www.mvps.org/access/forms/frm0031.htm

Nic;o)
Jul 7 '08 #4
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hmm... I just can't see why are you trying to 'load records' into your subform in this laborious way. There's loads of ways to do it, but in all honesty trying to load data by overwriting fields on the form is not going to be the way forward for you.

If you want to use code why not just add the records to the subform's recordset using the normal methods available? Use recordsetclone to copy the subform's recordset, open the cloned recordset, add the new records using the Addnew method, set the field values, then use Update to store the record. When complete, close the recordset, and copy it back to the form concerned. Look up help on Addnew for code samples.

Alternatively, and more simply, if you are appending records to your recordset you can run an update query in SQL then requery the subform to refresh its recordsource.

If you are not appending records at all and you need to change your recordsource dynamically in response to user selections say you can change the form's recordsource in code to another recordset in one step instead of loading records one at a time. For a subform the syntax is
Expand|Select|Wrap|Line Numbers
  1. forms!formname!subformname.form.recordsource = recordsetname
or for an SQL statement
Expand|Select|Wrap|Line Numbers
  1. forms!formname!subformname.form.recordsource = "SELECT stuff FROM sometable ORDER BY somefield"
-Stewart
Jul 8 '08 #5
MikeTheBike
639 Recognized Expert Contributor
Hi again

Never like to leave a problem unsolved, but in view of Stewert's last post, which could not agree with more, I am reluctant to post the solution(s) I have for manupulating the sub-form records.

If it is felt this is the only way possible (which it obviously isn't) then I will post what I have, but I suggest one (or more) of Stewert suggestions are tried first.


MTB
Jul 8 '08 #6
Ian Norris
5 New Member
Thank you all for all your help and suggestions. I have implemented Stewart's SQL example solution and that works fine.
I was not aware that option was available. I'll store it away for future reference.

Ian
Jul 8 '08 #7

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

Similar topics

2
by: nic | last post by:
Hi I am currently having problems getting two forms to behave the way I want. I have two tables Student and Application, and their respective forms. (Tables)Student has StudentID (PK) & an...
3
by: Nicolae Fieraru | last post by:
Hi All, I have a problem and I can't figure out how to solve it. My database has three tables: tblCustomers, with CustomerId and CustomerName tblProducts, with ProductId and ProductCode...
5
by: Susan Bricker | last post by:
Hi. I have a Main form with a subform that has a subform. I have an 'Add Event' button on the Main Form that issues the following instruction: DoCmd.GoToRecord , , acNewRec If the record...
1
by: sasan3 | last post by:
I have a main form "topform" contaning "subform1" and "subform2" The goal is: I need to requery subform2 on CURRENT event of subform1, and I need to load subform2 contents based on settings on...
2
by: Welie | last post by:
I apologize if this is a faq. I searched for about 45 minutes and didn't find a good answer but there are many matching posts. I have a form which is based on a simple query to a linked table....
1
by: kenduron | last post by:
Hello together! How would you manage the following termin: I got table "A" and table "B" I have to show most of the fields in "A", an one columm in table "B". But table "B" can have...
1
by: google | last post by:
I have a form with several subforms. Users enter the data, then on the parent there is a command button that runs code to generate a .pdf document from a report based on the data they are working...
1
by: maffonso | last post by:
Hi people, My main form has a subform nested with another subform, both subs work as a subDatasheet. Indeed I keep the mainForm just to put some filters. Whenever I open de MainForm I have no...
8
by: Michael R | last post by:
Hi everyone. I have a few subforms in the main form that are dependent on each other with their data (not with child/master fields). Sometimes I get an invalid reference error because the...
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
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
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.