473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

VBA for creating new record and copying data

2
I'm moderately handy with Access but haven't any coding training/experience with VBA - but from other posts I've read I think I need to use it to do what I want.

I have a form called Work Items in which I have a subform called Documents & Work Items subform. There's a button in the Work Items form which opens a form called Documents to a blank record.

What I want is for users to be able to enter details in the Documents form, then when they click a button, a new record needs to be created in the Documents & Work Items subform with the autonumber value in the Doc ID field from the Documents form copied into it.

And I've no idea how to do it.

Any help would be greatly appreciated.
Apr 2 '07 #1
3 1231
MMcCarthy
14,534 Expert Mod 8TB
In the On Close event of the Documents form you will need something like the following code.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.  
  3.    Forms![Work Items]![Documents & Work Items].Form![DocID] = Me!DocID
  4.    Forms![Work Items]![Documents & Work Items].Requery
  5.  
  6. End Sub
  7.  
Mary
Apr 2 '07 #2
pjg
2
In the On Close event of the Documents form you will need something like the following code.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.  
  3.    Forms![Work Items]![Documents & Work Items].Form![DocID] = Me!DocID
  4.    Forms![Work Items]![Documents & Work Items].Requery
  5.  
  6. End Sub
  7.  
Mary
Thanks for this. It doesn't quite work though. I've checked and rechecked the form and field names but it keeps returning this error message.

"Microsoft Office Access can't find the field 'Documents & Work Items subform' referred to in your expression."

Which seems weird - it's a subform not a field. Is there some reason it would be ignoring the .form on the end?
Apr 5 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Thanks for this. It doesn't quite work though. I've checked and rechecked the form and field names but it keeps returning this error message.

"Microsoft Office Access can't find the field 'Documents & Work Items subform' referred to in your expression."

Which seems weird - it's a subform not a field. Is there some reason it would be ignoring the .form on the end?
Open the Work Items form and go to the subform object. Open the properties window and make sure you've selected the subform object and not the subform itself (in other words click on the frame around the subform). Go to the Other tab and look at what is entered for the Name property. The subform object doesn't always have the same name as the subform.

Mary
Apr 5 '07 #4

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

Similar topics

2
by: Iain Miller | last post by:
Now this shouldn't be hard but I've been struggling on the best way as to how to do this one for a day or 3 so I thought I'd ask the assembled company..... I'm writing an application that tracks...
8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
2
by: Michael.Covington | last post by:
I am trying to create a DTS package using C#. I have done this in VB6 without any problems. However, when I convert everything over to C# I get the 'System.InvalidCastException'. I am running...
4
by: Nathan Moore | last post by:
Could anyone help write an SQL statement to take this: Table X ( key, Money, TheDate, first, last, ...) = ( 1, $1, #jan 4, 2006#, 'fred', 'willard', ...), ( 2, $4, #apr 1, 2006#, 'emanuel',...
1
by: Jimmy | last post by:
There is a command button on the form I'm working on. The form displays one record. The command button creates a new record by copying selected data from the current record: Dim dbs As Database...
1
by: OxfordConsult | last post by:
Hello, I have created a form that links with a table with the autonumber feature as its primary key. Whenever i create a new record in the form (using a command button ... i have disabled the...
3
by: Bartholomew Simpson | last post by:
I am writing some C++ wrappers around some legacy C ones - more specifically, I am providing ctors, dtors and assignment operators for the C structs. I have a ton of existing C code that uses...
10
by: jacc14 | last post by:
Hi I am sure there is an easy way to do this but I have exhausted all avenues. I have some label data in a table which I want to copy to an identical table. However the first label I may only...
19
by: emanning | last post by:
Using Access 2003 and using a form that's mostly bound. I need a way to tell if user-1 is on the record when user-2 tries to open the same record, w/o waiting for the user-1 to save the record...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.