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

Can I use a RecordSetClone in SQL

Hello

Can I write an SQL statement in code using a RecordSetClone of an open form?

something like:
MySQL = "UPDATE Me!Child0.Form.RecordSetClone SET
Me!Child0.Form.RecordSetClone.MyField = -1:"
DoCmd.RunSQL MySQL

Note: in the above example MyField is the Control Source of a Textbox in
Me!Child0 subform
(The above example gives me "Syntax error in Update statement" )

If it is possible to use a RecordSetClone in an SQL how would I write the
statement?

Thanks
G.Gerard
May 27 '06 #1
3 6149
No.

May 28 '06 #2
G Gerard wrote:
Hello

Can I write an SQL statement in code using a RecordSetClone of an open form?

something like:
MySQL = "UPDATE Me!Child0.Form.RecordSetClone SET
Me!Child0.Form.RecordSetClone.MyField = -1:"
DoCmd.RunSQL MySQL

Note: in the above example MyField is the Control Source of a Textbox in
Me!Child0 subform
(The above example gives me "Syntax error in Update statement" )

If it is possible to use a RecordSetClone in an SQL how would I write the
statement?

Thanks
G.Gerard


Here is some code I tried behind a form:

'-------Begin code behind form
Private Sub cmdRename_Click()
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim strSQL As String

Set MyDB = CurrentDb
strSQL = "SELECT EFirstName FROM tblEmployees WHERE EID = 1;"
Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenDynaset)

Call UpdateRecordset(MyDB, MyRS)
MyRS.Close
Set MyRS = Nothing
Set MyDB = Nothing
Me.Requery
MsgBox ("Done.")
End Sub

Private Sub UpdateRecordset(MyDB1 As DAO.Database, MyRS1 As
DAO.Recordset)
If MyRS1.Fields(0) = "Joe" Then
MyRS1.Edit
MyRS1(MyRS1.Fields(0).Name) = "Frank"
MyRS1.Update
End If
End Sub
'-------End code behind form

Note: I get to reuse a table from a different example.

tblEmployees
EID AutoNumber
EFirstName Text
ELastName Text

EID EFirstName ELastName
1 Joe Young
2 King Kong
3 The Hulk

After clicking on the command button the table becomes:

EID EFirstName ELastName
1 Frank Young
2 King Kong
3 The Hulk

The A97 help file states that the RecordsetClone is read-only so you
can't use it directly to update records.

I decided to make sure that bound values would not interfere with the
edit. I set the RecordSource of the form to tblEmployees and had a
textbox with a ControlSource bound to the EFirstName field. I changed
'Frank' back to 'Joe' in the table, then opened the form and clicked
the command button. The name in the textbox changed to 'Frank' just
before the 'Done.' message popped up.

James A. Fortune
CD********@FortuneJames.com

If a police car, an ambulance, a fire truck and a mail truck all meet
at an intersection the mail truck has the right of way. -- James Allen

May 28 '06 #3
G Gerard wrote in message
<i6********************@ursa-nb00s0.nbnet.nb.ca> :
Hello

Can I write an SQL statement in code using a RecordSetClone of an
open form?

something like:
MySQL = "UPDATE Me!Child0.Form.RecordSetClone SET
Me!Child0.Form.RecordSetClone.MyField = -1:"
DoCmd.RunSQL MySQL

Note: in the above example MyField is the Control Source of a Textbox
in Me!Child0 subform
(The above example gives me "Syntax error in Update statement" )

If it is possible to use a RecordSetClone in an SQL how would I write
the statement?

Thanks
G.Gerard


I think it should be possible to do something like this

strSql = "UPDATE " & Me!Child0.Form.RecordSetClone.Name & _
" SET MyField = -1"
currentdb.execute strSql, dbfailonerror
Me!Child0.Form.Requery

as long as the form recordset is DAO and the recordsource specifies a
table or query which is updateable (not an SQL string).

Or do you also wish to pick up the controlsource dynamicly?

strSql = "UPDATE " & Me!Child0.Form.RecordSetClone.Name & " Set " & _
Me!Child0.Form.Controls("MyField").Controlsource & " = -1"

--
Roy-Vidar
May 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Seth Spearman | last post by:
Hey guys, I have the following code: '****************************************************** If Not Me.NewRecord Then Dim rs As DAO.Recordset Dim strBookmark As String Set rs =...
1
by: Gerry Abbott | last post by:
Hi all, I have a function I use to sort the recordset behind a form on designated fields of the form (see code below). I pass the field name, and trigger this function with the click of the...
3
by: Anthony Kroes | last post by:
I have a subform on a form and they are not linked. On the main form is a text box where the user types in a number. When that number changes, I have some code to make the corresponding text...
3
by: Ian Bailey | last post by:
I have developed a routine that opens a number of forms with each form being positioned on a particular record. I am using the Recordsetclone to find the record and then setting the form bookmark...
3
by: GGerard | last post by:
Hello I am trying to refer in code to the RecordsetClone of a subform datasheet but I'm getting syntax errors. This is what I am writing: Set MyDB = DBEngine.Workspaces(0).Databases(0)...
22
by: Br | last post by:
First issue: When using ADPs you no longer have the ability to issue a me.refresh to save the current record on a form (the me.refresh does a requery in an ADP). We usually do this before...
10
by: d.francis | last post by:
I have converted an Access 97 database to Access 2003 The following code now fails and returns Run-time error '3420' Dim rst as DAO.recordset Set rst = Forms!frm1!frm2.Form.RecordsetClone I...
2
imrosie
by: imrosie | last post by:
Hello, I have a search form that uses a row query to locate a customer by customerID and first & last names, so it's an unbound control. I also have two events associated with this control,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.