473,624 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

automatically insert foreign key in subform

72 New Member
Hi, I am adding records in a subform using recordsetclone. The subform has Data Entry property set to no and Add Record set to no. The main form PK is linked to the child form fk.
At the moment I am having to add the fk manually to the recordsetclone but I was wondering if that is the default behaviour? Why isn't the fk added automatically by Access? I suppose it is because the record is not written directly on the form but I just wanted to check if I am correct or I am talking nonsense. Thanks

Expand|Select|Wrap|Line Numbers
  1. Private Sub addPayment(button As Integer)
  2.  
  3.     On Error GoTo ErrorHandler
  4.  
  5.     Dim rst As DAO.Recordset
  6.  
  7.     Set rstClone = Me.PayChild.Form.RecordsetClone
  8.     Set rst = Me.PayChild.Form.Recordset
  9.  
  10.     With rstClone
  11.         .AddNew
  12.             !fkPaymentTypeID = button
  13.             !fkInvoiceID = Me!InvoiceID
  14.         .Update
  15.         rst.Bookmark = .LastModified
  16.     End With
  17.  
  18.     With Me.PayChild
  19.         .SetFocus
  20.         .Form!txtPaymentAmount.SetFocus
  21.          Debug.Print Me.Dirty
  22.         .Form.Dirty = True
  23.     End With
  24.  
  25. ExitSub:
  26.     Set rst = Nothing
  27.     Set rstClone = Nothing
  28.     Exit Sub
  29. ErrorHandler:
  30.     MsgBox "Error No: " & Err.Number & vbNewLine _
  31.          & "Error Details: " & Err.Description & vbNewLine _
  32.          & "Error in Sub: frmPay\addPayment"
  33.     Resume ExitSub
  34.  
  35. End Sub
Oct 23 '17 #1
3 2662
NeoPa
32,567 Recognized Expert Moderator MVP
When properly linked a subform will find the link to the main form populated for it automatically. However, that is only through the subform's interface - not when done via code directly to another recordset.

Of course, if the subform in question doesn't allow adding new records at all then adding it via the form itself will be a problem in itself. If you're already adding it to .RecordsetClone then you may find adding the FK yourself the easiest option.
Oct 30 '17 #2
Neruda
72 New Member
Great thanks, it was bugging me!
Oct 30 '17 #3
NeoPa
32,567 Recognized Expert Moderator MVP
Never a problem. I love helping people with an interest in Access.
Oct 30 '17 #4

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

Similar topics

0
1911
by: Peter | last post by:
Hi, I need some advice. I've a program running on a local machine which automatically pushes images from a camera to our webserver (linux/mysql) through FTP. I want to store those images in the database so I think I need some perlscript running as a deamon that looks for new incoming images. I tried to find a script which does the job but with no success. I've DBI::mysql installed. Does anybody have some experience on this matter or is...
4
20647
by: Dave | last post by:
Hi, Can anyone tell me a simple way of inserting some sort of code into a Dreamweaver template (it goes at the bottom of the page in Copyright info) that will cause the current year to be automatically inserted at spot X when the pages are viewed that were produced from the template or are linked to it? Thanks Dave
0
1321
by: Sherman | last post by:
I am trying to insert an inkobject autmatically using vb in Access 2003. When one goes to a new record in my form, they can right click, insert object and then select the object of their choosing. However, I would like to do this automatically. The object I am trying to insert is an Ink object for tablet PCs. Any Help would be appreciated!
3
1458
by: Darren Li | last post by:
Hi: Can I stop VS.NET 2003 IDE automatically insert <font> tag into the asp.net web form design view? It just keep inserting that tag with the font I don't want to use. I search document property, body property, tools/options, I just can not find a place to turn it off! Please help! Thanks.
3
1090
by: Mike | last post by:
I don't think this is possible, but wanted to check anyways. I have the following line of code in the Page_Load() event of every webform within as asp.net project... Dim GiftPurchase As AccountingLogic.Detroit.GiftPurchase Is there anyway I can have this automatically appear for each new webform I create, so I don't have to keep typing it? Thanks.
3
2645
by: Wolfgang Meister | last post by:
Is there a way to let VisualStudio insert automatically (after pressing e.g. F7) missing "Using" statements at the top ? Or is there a menu which suggests inserts for using directives ? How can I otherwise find out which "using" I have to add for e.g. "StreamWriter" or "File"
0
187
by: Peter Wang | last post by:
"gita ziabari" <gitaziabari@gmail.comwrites: Why not use VBA for that work?
17
17483
by: msmjsuarez | last post by:
Hello, I need help... How to automatically insert data to mysql database without submit button using php? Is there a way on this? thanks a lot.
1
2105
by: Mohd Naiem | last post by:
How can insert foreign in database key from dropdown selected values in asp.net
4
1497
by: deamond | last post by:
Hello everyone.. I'm on my way on creating a simple Database for a company. This database contains several tables, one of the tables will record information about the training that had been completed by each employee. There are about ten sections of training that should be completed. Regarding to the database, I have two tables called 'Development' and 'CSA_Lisence'. 'Development' is the table that record the information about training...
0
8240
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8680
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...
1
8336
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8482
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
7168
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
6111
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
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
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
1
1791
muto222
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.