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]! - = !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.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.
6 5071
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
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.
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 - forms!formname!subformname.form.recordsource = recordsetname
or for an SQL statement - forms!formname!subformname.form.recordsource = "SELECT stuff FROM sometable ORDER BY somefield"
-Stewart
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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).
|
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
|
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...
| |
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.
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |