473,799 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ 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.GoToRecor d , , 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 5071
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.GoToRecor d , , 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.GoToRecor d , , 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.GoToRecor d 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
1753
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 ApplicationID. And Application has ApplicationID as its primary key. With the main Form being the Student_Details form, I have a Button which loads the Application Form. The way I want it to behave is when the Load_AppForm button is clicked the...
3
4506
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 tblPurchases, with PurchaseId, CustomerId and ProductId I created a form with a subform which shows all the customers, one at a time
5
3487
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 being displayed BEFORE the 'Add Event' button is clicked does not have data to be displayed (no associated linked records) then when the 'new record' is displayed, the innermost subform looks just fine (all the controls are there and they are empty).
1
1638
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 subform1. The problem is: Order of loading is: subform1 subform2
2
1737
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. The data is set to no edits,additions,deletions,dataEntry. If the form is open, but the linked table is opened seperately in design mode, than a message appears saying "the table is already opened exclusively by another user". Which makes perfect...
1
1899
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 several entries which belongs to A.
1
3239
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 with. If a user enters data in a subform, then directly clicks the command button on the parent form, the data in the subform is not included in their document. I THOUGHT that as soon as focus left the subform, any pending changes to the data...
1
2195
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 problems. The mainForm opens and show the subform in shape of subDatasheet. The problem is that the sub-subForm doenst load unless I click on the subform. If the subform doesnt load its impossible to refer to it via code. Everytime I try to refer to...
8
1920
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 referenced subform isn't loaded (yet). To make them load in the correct order I need to delete them all, then insert them one by one in a correct order. If, later on, I decide to edit one of them of or send it to background, the order breaks and once again...
0
10473
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10249
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10025
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7563
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5461
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4138
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 we have to send another system
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.