473,387 Members | 1,493 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,387 software developers and data experts.

Copy from 1 subform to another

This is an existing topic. A good solution is given, but one line of code doesn't work:

rst2!Field2Update = Me.SF1Field

It has to do with Update.

What is the proper VBA syntax to update a field as shown above?

Thanks!
Feb 22 '12 #1
11 2004
NeoPa
32,556 Expert Mod 16PB
AmyWolfie:
This is an existing topic.
Please provide a link to the topic so that we can make sense of this question.
Feb 22 '12 #2
Yes, sorry. The original topic is at:
http://bytes.com/topic/access/answer...ubform-another
Feb 22 '12 #3
NeoPa
32,556 Expert Mod 16PB
The syntax seems fine to me. What problem are we trying to make sense of here for you?

I suspect we'll need to see your code, and your error message, with your line number of where the error occurs. For more details of how to post code so that we can work with it more easily see Before Posting (VBA or SQL) Code.
Feb 23 '12 #4
Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub PrimaryDataBatchID_AfterUpdate()
  2. On Error GoTo Error_Handler:
  3.  
  4.  'Appends DataBatchID to OK_DataBatchID since usually the same -- AW
  5.  
  6. Dim rst2 As Recordset
  7. Dim rst1 As Recordset
  8.  
  9. Set rst2 = Forms![frmMain]![subfrm_tblOverkeyDataBatchID].Form.RecordsetClone
  10. Set rst1 = Forms![frmMain]![subfrmgd_tblPrimaryDataBatch].Form.RecordsetClone
  11.  
  12. 'find the current record
  13. rst1.FindFirst "fk_OK = " & Me.fk_OK
  14. '"SF1ID = " & Me.SF1ID
  15.  
  16. rst2.MoveFirst
  17. Do While Not rst2.EOF
  18. If rst2.AbsolutePosition = rst1.AbsolutePosition Then
  19. rst2.Edit
  20. rst2!fk_OK2Update = Me.fk_OK
  21.  
  22. 'rst2!Field2Update = Me.SF1Field
  23. rst2.Update
  24. Exit Do
  25. Else
  26. rst2.MoveNext
  27. End If
  28. Loop
  29. rst1.Close
  30. rst2.Close
  31. Set rst1 = Nothing
  32. Set rst1 = Nothing
  33.  
  34. Exit Sub
  35.  
  36. Error_Handler:
  37.     MsgBox Err.Number & " " & Err.Description
  38.  
  39. End Sub
====

Line #20 : Error 3265 Item not found in this collection

If I remove the 'Update' I get no error, but nothing happens either.

Thanks!

Thanks.
Feb 23 '12 #5
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. rst2!fk_OK2Update = Me.fk_OK
As Me.fk_OK is referred to (presumably) without problems on line #13, I would say this idicates that rst2!fk_OK2Update is somehow an invalid reference. I suspect fk_OK2Update is not the name of a field in that recordset. The confusion may be that it's the name of a control on the form which the recordset drives perhaps?
Feb 23 '12 #6
hjozinovic
167 100+
Amy,
you are having problem with using RecordsetClone property.
This property is Read-only. That is why you can't update your data.
You should use Recordset property instead. Try this:
Expand|Select|Wrap|Line Numbers
  1. Set rst2 = Forms![frmMain]![subfrm_tblOverkeyDataBatchID].Form.Recordset
  2. Set rst1 = Forms![frmMain]![subfrmgd_tblPrimaryDataBatch].Form.Recordset
  3.  
Feb 23 '12 #7
NeoPa
32,556 Expert Mod 16PB
hjozinovic:
you are having problem with using RecordsetClone property.
This property is Read-only. That is why you can't update your data.
Are you saying that the RecordsetClone recordset is actually non-updatable?
The property being Read-Only would not effect the ability to update data via the dataset of course ;-) I suspect it's just confusion of terminology.
Feb 23 '12 #8
The actual field name is fk_Ok2

The original code on this topic read:

SB2Key2Update

So I added "Update" to the field name. When I remove, the code runs, but no updates actually happen.

Thanks.
Feb 23 '12 #9
NeoPa
32,556 Expert Mod 16PB
Regardless of the original code, the name in your code must match the name of the field in your project, not the name of someone-else's.

NB. Make sure you understand the difference between the terms Field and Control. It's no good using the name of the control to try to refer to the field.

hjozinovic:
You should use Recordset property instead.
Have you tried the suggestion from post #7? If so, what did you find.
Feb 23 '12 #10
hjozinovic
167 100+
@NeoPa
I had problems simulating this situation because Access kept crashing down. I looked up the explanation in Help and here is what I found:
"You can use the RecordsetClone property to refer to a form's Recordset object specified by the form's RecordSource property. Read-only.

Remarks
The RecordsetClone property setting is a copy of the underlying query or table specified by the form's RecordSource property. If a form is based on a query, for example, referring to the RecordsetClone property is the equivalent of cloning a Recordset object by using the same query. If you then apply a filter to the form, the Recordset object reflects the filtering.

This property is available only by using Visual Basic and is read-only in all views."

I thought the problem might be referring to RecordsetClone, but now I made test database and got the correct results using RecordsetClone. So....I was wrong in my first post.
Feb 24 '12 #11
NeoPa
32,556 Expert Mod 16PB
hjozinovic:
So....I was wrong in my first post.
Nevertheless, it was good thinking, and was worth posting and delving into further.
Feb 24 '12 #12

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

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
0
by: Nicholai Yu | last post by:
Hi everyone I know only some about .net and C# but nothing about Windows API and Shells and etc. So if this is not possible please tell me. I want to copy a text from another process (from IE...
4
by: Yudan Yi | last post by:
I have a problem to copy (assign) a matrix to another matrix. Curreny, I know copy the number using loops, while it will take some time, I wonder if there have faster method. The following code...
8
by: Jesper | last post by:
Hi, Does the concept "copy constructor" from c++ excist in c#. What is the syntax. best regards Jesper.
10
by: Steve Bostedor | last post by:
Does anyone have an example of how to file.copy as another user? Do I create a new thread as another user? How is that done? Thanks!
4
by: Idit | last post by:
Hi, I am running C# application with MFC. dll project. I managed to run the application when the VS2005 environment exists but when I copy the .exe and dll to another computer I get the following...
2
by: TonyJ | last post by:
Hello! I use System.IO.File.Copy(exeFileServer,exeFileLocal); and this exeFileServer is located on another computer node in the network I want to catch the error by using try...catch if this...
9
by: Trevor2007 | last post by:
Hi Everyone, Im New here, I am trying to copy the contents of a subform(Datatsheet view)and populate the subform(datasheetview) on the next screen with the contents it just copied from the...
4
by: JDVOIGT | last post by:
I am building a P&L on worksheet(1) based on data from worksheet(2). I need to copy rows of data from worksheet(2) and paste onto worksheet(1). The pasting process needs to find a named range (one...
5
Fspinelli
by: Fspinelli | last post by:
I need to keep copies of deleted records. Say there is a contact/record the end user no longer needs from our Contact database. He wants a button to delete the record. Our compliance officer...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.