By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

AddNew record in subform and VBA

P: 5

I'm new in MS Access VBA programming and I'm having a little problem.

I had 2 tables

>Table 1
-no , autonumber
-blah blah
-dat2, text

>Table 2
-no, autonumber
-filesname, text

Table 2 is a subform in the main form.
Table1 [no] > Table2 [no] one to many.

When I'm adding manually new records in the form the Table2 [no] field take automatically the same number with the Table1 [no] field.

When I'm adding new records through VBA the autonumber fields didn't match.

I'm using the following code
Expand|Select|Wrap|Line Numbers
  1. With Me.[Table 2].Form.RecordsetClone
  2. .AddNew
  3. !filesname = fName
  4. .Update
  5. End With
Can anyone help me?

Jan 9 '07 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 31,494
If there is a One-to-Many relationship between the two tables then you cannot have the same field (Table2.No) as both a Primary Key AND a Foreign Key.
This doesn't really make much sense.
You need to add Table1.No to Table2 into a different field.
Jan 9 '07 #2

P: 5
I'm trying your suggestion.
Now there is a little problem when I add records manually :) but i can solve it

Thanks Neopa!
Jan 10 '07 #3

Expert Mod 15k+
P: 31,494
I'm pleased to help.
If you encounter more problems just let us know :)
Jan 10 '07 #4

Post your reply

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